Rule Support in JUnit 5

Understand how the Rules are supported in JUnit 5.

JUnit 4 supports the extension model using a concept called Rules. They’re equivalent to extensions in JUnit 5.

To run these rules, JUnit 4 provides @RunWith annotation, whereas JUnit 5 uses the @ExtendWith annotation.

The @Rule annotation is used to define rules in JUnit 4.

Code example using @Rule

Get hands-on with 1400+ tech skills courses.