Menu

#969 Asserts are not found in other methods

open
pmd (543)
5
2012-10-07
2011-06-08
Anonymous
No

This rule net.sourceforge.pmd.rules.junit.JUnitTestsShouldContainAsserts
The rule complains there are no "asserts" found in a test method.
The asserts are actually in separate helper methods.

I do this when I have a common set of assertions. I put them into a helper method. Then I have the test methods call that helper method.

e.g.
@Test
public void testSomeStrings() {
testSomeString("test1");
testSomeString("test2");
testSomeString("test3");
}

private void testSomeString(String str) {
Assert.assertNotNull("The string was null.", str);
}

Discussion


Log in to post a comment.