One of the most significant innovations introduced in JUnit 4 was the use of rules. Rules allow flexible addition or redefinition of the behavior of each test method in a test class. A rule should be included in a test case by annotating a class attribute with the annotation @Rule. The type of this attribute should inherit the JUnit interface org.junit.rulesTestRule. The following rules are provided out of the box in JUnit 4:
- ErrorCollector: This rule allows execution of a test to continue after the first problem is found
- ExpectedException: This rule allows to verify that a test throws a specific exception
- ExternalResource: This rule provides a base class for Rules that set up an external resource before a test ...