S2699 False positive

406 views
Skip to first unread message

gboc...@gmail.com

unread,
Nov 19, 2015, 7:25:12 AM11/19/15
to SonarQube
S2699: "Tests should include assertions"

In my opinion, this rule should consider the cases in which the assertions are placed into methods called by the methods which are marked as unit tests.

Sample (stupid) code:

@Test
public void testFoo() {
   checkSomething
();
}

private void checkSomething() {
   assertTrue
(true);
}



I think it's a common practice to factorize methods in unit tests to avoid code duplication.



Nicolas Peru

unread,
Nov 19, 2015, 8:19:34 AM11/19/15
to gboc...@gmail.com, SonarQube
Hi, 

While I agree that this can be a common pattern we are unforunately not able to detect those at the moment : when the method is in the same source file we could probably do some trick to manage that but when it is not the case we still don't have the tools required to do this. Cross procedural analysis is definitely something we want to achieve at some point but we are not yet able to deal with this. So for now the answer to your issue is unfortunately : either mark the issue as false positive or deactivate the rule. 

Cheers,

Nicolas PERU | SonarSource
Senior Developer
http://sonarsource.com


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/2fa0395d-df28-4f30-a0cc-251443dd511e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Giacomo Boccardo

unread,
Nov 19, 2015, 9:24:33 AM11/19/15
to SonarQube, gboc...@gmail.com
Hello,
   thanks for your quick reply. Unfortunately I have hundreds of those false positives, so I'll deactivate the rule.

Kind regards,

Giacomo Boccardo

Nick Radov

unread,
Jun 24, 2016, 6:58:39 PM6/24/16
to SonarQube, gboc...@gmail.com
We are also getting a lot of false positive issues due to this problem. I would appreciate it if you could expedite the implementation of cross procedural analysis.

Daniel Sobral

unread,
Jul 20, 2016, 6:18:42 PM7/20/16
to SonarQube, gboc...@gmail.com
My suggestion is that you transform the method into a Hamcrest assertion, so you can use it with assertThat. 

milk...@web.de

unread,
Sep 8, 2016, 8:50:25 AM9/8/16
to SonarQube
Hi Nicolas. 
We also suffer lot of false positives because of some common helper methods used in tests.

Is there already a JIRA issue for implementing "Cross procedural analysis" which we could track to get informed when it becomes implemented?

Bye,
 Horst

Freddy Mallet

unread,
Sep 9, 2016, 4:57:12 AM9/9/16
to SonarQube
@Guys, here is a first MMF we're currently working on : https://jira.sonarsource.com/browse/MMF-256 to first support cross-procedural analysis inside a source file.

And be sure that it is one of the TOP priorities at SonarSource. But obviously, we're not talking about a trivial development so indeed to do it properly this takes some time. 

Thanks for your understanding
Freddy


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Freddy MALLET | SonarSource
Product Director & Co-Founder
http://sonarsource.com
Reply all
Reply to author
Forward
0 new messages