Migration from JUnit 4 to JUnit 5

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 custom rule

@Repeated

Dynamic tests

NA

@TestFactory

Test templates

NA

@TestTemaplate

Runners

@RunWith

This feature is superseded by the extension model (@ExtendWith)

Rules

@Rule and @ClassRule

This feature is superseded by the extension model (@ExtendWith)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.244.250