Affects PMD Version: 7.x (current)
Rule:
UnitTestShouldIncludeAssert
https://docs.pmd-code.org/latest/pmd_rules_java_bestpractices.html#unittestshouldincludeassert
Description:
The UnitTestShouldIncludeAssert rule reports violations for nested test classes that use injected SoftAssertions when the extension is declared on a parent (or grandparent and higher) class
@ExtendWith annotation is inherited by nested clases, so the extension from parent applies there too. Currently PMD recognize the soft assertions only when the extension is applied in the same class.
Code Sample demonstrating the issue:
@ExtendWith(SoftAssertionsExtension.class)
class SomeTest {
@Nested
class NestedTest {
@Test
void nestedTest(SoftAssertions softly) {
softly.assertThat(42).isEqualTo(42);
}
}
}
Expected outcome:
PMD reports a violation at line 6, but that's wrong. That's a false positive.
Running PMD through: Gradle