[java] JUnitTestsShouldIncludeAssert false positive with inherited @Rule field #1422
Labels
a:false-positive
PMD flags a piece of code that is not problematic
Milestone
Affects PMD Version: 6.9.0
Rule: JUnitTestsShouldIncludeAssertRule
Description: Thanks to bug #631, this rule properly looks for
@Rule ExceptedException
fields, and correctly does not complain about tests that use them. However, it only checks for such rules in the current class. One scenario that's come up in my students' code is writing an abstract test class with a bunch of concrete tests and an abstract factory method, and then several concrete test classes that instantiate the factory with one of several implementations. Additionally, they write some concrete tests in the concrete classes. Now, the@Rule
isn't a declared field in the same class as the@Test
s that use it, so this rule incorrectly fires again.I think the solution is extending here to walk up the inheritance tree, so far as it's known (and here, it should be known), and check for inherited
@Rule
fields...Code Sample demonstrating the issue:
Running PMD through: programmatically
The text was updated successfully, but these errors were encountered: