Spurious application of java:S5960 in testFixtures classes

Please provide

  • Operating system:macOS Ventura
  • SonarLint plugin version: 8.2.0.68615
  • Programming language you’re coding in: Java
  • Is connected mode used: No

And a thorough description of the problem / question:
If you define reusable classes for unit testing following gradle standards in ‘testFixtures’ and those classes make use of junit assertions (e.g., org.junit.jupiter.api.Assertions.assertTrue), Sonarlint flags a bug that “Assertions should not be used in production code”.

Hey @cssprs ,

It seems to me that in this case, you are reaching the current limit of our rule classification. Rule java:S5960 is explicitly trying to identify the wrong use of assertions in production code… Buch such calls are always going to be valid when designing a testing frameworks.

Unfortunately, there is no way to let our analyzer know that it is analyzing a project aiming at tests… and so this rule is non-sensical in this context. I would encourage you to ignore the issues and mark them as won’t fix (or disable the rule).

Cheers,
Michael