Take care of your assertions with rules dedicated to AssertJ

Hello Java developers,

We recently released a set of rules to help you write better unit tests with JUnit. Following this first step we continued our effort and released a set of rules dedicated to AssertJ to help you write maintainable and bug free assertions.

Here is the full list of the new rules:

Bug Rules:

  • S5845: Assertions of dissimilar types should not be made (Critical)
  • S5863: Assertions should not compare an object to itself (Major)
  • S5831: AssertJ configuration should be applied (Major)
  • S5833: AssertJ methods setting the assertion context should come before an assertion (Major)
  • S5841: AssertJ assertions “allMatch” and “doesNotContains” should also test for emptiness (Minor)

Code Smell Rules:

  • S5838: Chained AssertJ assertions should be simplified to the corresponding dedicated assertion (Minor)
  • S5853: Consecutive AssertJ “assertThat” statement should be chained (Minor)

For more information, you can check the changelog.

These features are already available on SonarCloud, and will be included soon in SonarQube 8.4 and SonarLint.