-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
OLD Prototype JUnit4 Run And Migrate
Although the JUnit 5 programming model and extension model will not support JUnit 4
features such as Rules and Runners, it is not expected that source code maintainers
will need to update all of their existing tests, test extensions, and custom build test
infrastructure to migrate to JUnit 5.
Instead, JUnit 5 provides a gentle migration path via a JUnit 4 test engine which
allows existing tests based on JUnit 4 to be executed using the JUnit 5 infrastructure.
Since all classes and annotations specific to JUnit 5 reside under a new org.junit.gen5
base package, having both JUnit 4 and JUnit 5 in the classpath does not lead to any
conflicts. It is therefore safe to maintain existing JUnit 4 tests alongside JUnit 5
tests. Furthermore, since the JUnit team will continue to provide maintenance and bug
fix releases for the JUnit 4.x baseline, developers have plenty of time to migrate to
JUnit 5 on their own schedule.
Just make sure that the junit4-engine artifact is in your test runtime path.
In that case JUnit 4 tests will automatically be picked up by JUnit 5 test runners.
See the example projects in the junit5-samples repository to find out how this is done with Gradle and Maven.
The following are things you have to watch out for when migrating existing JUnit 4 tests to JUnit 5.
- Annotations reside in the
org.junit.gen5.apipackage. - Assertions reside in
org.junit.gen5.api.Assertions. - Assumptions reside in
org.junit.gen5.api.Assumptions. -
@Beforeand@Afterno longer exist; use@BeforeEachand@AfterEachinstead. -
@BeforeClassand@AfterClassno longer exist; use@BeforeAlland@AfterAllinstead. -
@Ignoreno longer exists: use@Disabledinstead. -
@Categoryno longer exists; use@Taginstead. -
@RunWithno longer exists; superseded by@ExtendWith. -
@Ruleand@ClassRuleno longer exist; superseded by@ExtendWith.