S2699 - Tests should include assertions - False Positive

129 views
Skip to first unread message

Michał Kordas

unread,
Jul 9, 2015, 3:32:08 PM7/9/15
to sona...@googlegroups.com


Hi,

I've just enabled the new rule and it caused 10,000 critical violations in my project :) Looks like AssertJ assertions are not recoginized correctly:



Thanks,
Michal Kordas

Nicolas Peru

unread,
Jul 10, 2015, 2:50:23 AM7/10/15
to Michał Kordas, sona...@googlegroups.com
Hi Michal,

Indeed AssertJ assertions are not searched, right now it will look for fest and junit assertions. 
As we are no assertJ experts, Would it be possible for you to list the common methods you are using in assertJ ? the fully qualified name of the type where the method is defined and its name (I guess that there are a lot of overloading so type of parameters would be tedious). That would really help to make this rule usable for assertJ users.

Thanks.

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/626b6dfe-ade5-4bb4-a415-8020022433c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Francis Galiegue

unread,
Jul 10, 2015, 3:10:55 AM7/10/15
to sona...@googlegroups.com, kordas...@gmail.com
Hello,


On Friday, July 10, 2015 at 8:50:23 AM UTC+2, Nicolas Peru wrote:
Hi Michal,

Indeed AssertJ assertions are not searched, right now it will look for fest and junit assertions. 
As we are no assertJ experts, Would it be possible for you to list the common methods you are using in assertJ ? the fully qualified name of the type where the method is defined and its name (I guess that there are a lot of overloading so type of parameters would be tedious). That would really help to make this rule usable for assertJ users.

Thanks.


This is valid for assertj 3.x.

Basically, anything which implements org.assertj.core.api.Assert<S, A> is an AssertJ assertion class. The most common way to obtain such an assertion is via the methods assertThat(...) of org.assertj.core.api.Assertions.

And so is any class extending AbstractSoftAssertions; note that since 2.x there is also AutoCloseableSoftAssertions as well.

Finally, there are also the static methods of Assertions which are called failBecauseExceptionWasNotThrown() and shouldHaveThrown().

Basically the structure doesn't fundamentally differ from fest, which is not very surprising since assertj was a clone of fest to begin with -- just not the same namespaces.

Regards

Michel Pawlak

unread,
Jul 10, 2015, 3:17:40 AM7/10/15
to sona...@googlegroups.com
Hi Nicolas,

AssertJ being a fork of fest, they are similar. Main features are described on this page : http://joel-costigliola.github.io/assertj/assertj-core-features-highlight.html and api on this one : http://joel-costigliola.github.io/assertj/core-8/api/index.html

Main assertions methods are in : org.assertj.core.api.Assertions including assertions from org.assertj.core.api.StrictAssertions superclass.

One key feature not to be missed is org.assertj.core.api.SoftAssertions. Note that while SoftAssertions require a call to assertAll(), the @Rule JUnitSoftAssertions does not require such a call.

Otherwise, a more generic rule is that if a method is a static method of a class that extends org.asserj.core.api.AbstractAssert or  org.asserj.core.api.AbstractSoftAssertions then it must be considered as an assertion (custom assertions are written by extending AbstractAssert)

Cheers,

Michel

Nicolas Peru

unread,
Jul 10, 2015, 4:29:42 AM7/10/15
to Michel Pawlak, sona...@googlegroups.com
Hi 
Thanks for your precisions Michel and Francis, 



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.

Massimo Paladin

unread,
Aug 11, 2015, 7:34:35 AM8/11/15
to Nicolas Peru, Michel Pawlak, SonarQube
The ticket has been fixed: http://jira.sonarsource.com/browse/SONARJAVA-1187

For your information, we also extended S2970 to catch incomplete assertJ assertThat:

Cheers,

Massimo PALADIN | SonarSource
Software Developer @ Language Team
http://sonarsource.com

Reply all
Reply to author
Forward
0 new messages