JUnit tests should include at least one assertion. Using a message for each assertion makes the reason for failure more clear and makes the test easier to maintain and debug.

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

  • No labels