Details
Recommendation type: No assertions
Configurable in Preferences: Yes
Filter category: Assertions
Description
UTA displays this recommendation when a test does not include any assertions. Each JUnit test should have at least one assertion. Each assertion should have a message that explains why the test failed to facilitate maintaining and debugging the test.
UTA does not display this recommendation for tests that have an expected exception specified with the @Test(expected=...)
annotation, the assertThrows()
method, or @Rule
ExpectedException
.
Example
public class Foo extends TestCase { public void testSomething() { Bar b = findBar(); // This is better than having a NullPointerException // assertNotNull("bar not found", b); b.work(); } }
Source: http://pmd.sourceforge.net/pmd-4.3.0/rules/junit.html