Rule Set: JUnit
Description: Currently, the JUnitTestsShouldIncludeAssertRule checks whether a method is annotated @Test(expected = ...class)
to check for expected exceptions. JUnit4 includes the @Rule
form to define ExpectedException
s, too, but if code uses that, then the rule above will fire and complain that no assertions were found.
Code Sample demonstrating the issue:
(Excerpted from https://github.com/junit-team/junit4/wiki/Rules)
public class DigitalAssetManagerTest { @Rule public final ExpectedException exception = ExpectedException.none(); @Test public void throwsIllegalArgumentExceptionIfIconIsNull() { exception.expect(IllegalArgumentException.class); exception.expectMessage("Icon is null, not a file, or doesn't exist."); new DigitalAssetManager(null, null); } }
It seems to me the rule needs to check:
@Test
method that isn't annotated with an expected = ...class
attribute,@Rule
-annotated ExpectedException
field in that test's class,.expect(...class)
call within the test? (I think the expectMessage
call is inessential elaboration, for the purpose of this rule.)I tried writing this rule in XPath, but got stymied trying to match up the field name correctly...
Running PMD through: CLI
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4