All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.pmd.rules.pmd-unit-tests.JUnitTestContainsTooManyAsserts.html Maven / Gradle / Ivy

Go to download

PMD is a tool that looks for potential problems like possible bugs, dead code, suboptimal code, overcomplicated expressions or duplicate code.

There is a newer version: 2.4
Show newest version
JUnit tests should not contain too many asserts.  Many asserts are indicative of a complex test, for which 
it is harder to verify correctness.  Consider breaking the test scenario into multiple, shorter test scenarios.  
Customize the maximum number of assertions used by this Rule to suit your needs. Example: 
public class MyTestCase extends TestCase {
	// Ok
	public void testMyCaseWithOneAssert() {
		boolean myVar = false;		
		assertFalse("should be false", myVar);
	}

	// Bad, too many asserts (assuming max=1)
	public void testMyCaseWithMoreAsserts() {
		boolean myVar = false;		
		assertFalse("myVar should be false", myVar);
		assertEquals("should equals false", false, myVar);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy