SonarQube issue "Add at least one assertion to this test case" for unit test with assertions?

The rule S2699 (Tests should include assertions) from the SonarQube Java Analyzer does not perform cross-procedural analysis and only explore body of methods being identified as test method (usually annotated with @Test).

Consequently, if the only assertions which will be called when executing the test method are done by a dedicated method (to avoid duplication), then the rule will raise an issue. This is a known limitation of the rule and we will deal with it only when we will be able to efficiently perform cross-procedural analysis.

Regarding the issues raised by SonarQube on such cases, you can safely mark them as Won't Fix.

Regarding the detected assertions, the rule consider as assertions the usual assert/fail/verify/expect methods from the following (unit test) frameworks :

  • JUnit
  • Fest (1.x & 2.x)
  • AssertJ
  • Hamcrest
  • Mockito
  • Spring
  • EasyMock

If you don't expect any exception to be throw from your test, this can be a workaround:

@Test(expected = Test.None.class /* no exception expected */)

Alternatively, you can suppress the warning for the test method/test class:

@SuppressWarning("squid:S2699")