JUnit 5 does not support JUnit 4 features, such as Rules and Runners, natively. Nevertheless, JUnit 5 provides a gentle migration path via the JUnit Vintage test engine, which allows us to execute legacy test cases (including JUnit 4 but also JUnit 3) on the top of the JUnit Platform.
The following table can be used to summarize the main differences between JUnit 4 and 5:
Feature |
JUnit 4 |
JUnit 5 |
Annotations package |
org.junit |
org.junit.jupiter.api |
Declaring a test |
@Test |
@Test |
Setup for all tests |
@BeforeClass |
@BeforeAll |
Setup per test |
@Before |
@BeforeEach |
Tear down per test |
@After |
@AfterEach |
Tear down for all tests |
@AfterClass |
@AfterAll |
Tagging and filtering |
@Category |
@Tag |
Disable a test method or class |
@Ignore |
@Disabled |
Nested tests |
NA |
@Nested |
Repeated test |
Using... |