O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required