-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Upgrading to JUnit 6.0
This page provides guidance on upgrading from JUnit 5.x.y to 6.0.0
This is currently a work in progress.
Migrating from JUnit 5.x.y to 6.0.0 should be much easier than migrating from 4.x to 5.x. Only APIs that have been deprecated for more than X have been deleted. All other APIs continue to be supported, making version 6.0.0 a drop-in replacement in most cases.
JUnit 6.0.0 increases the following baselines:
- Java 17 (was 8)
- Kotlin 2.2 (was 1.6)
Therefore, if your project uses earlier versions of Java and/or Kotlin, you should first switch to Java 17 or later and/or Kotlin 2.2 or later.
To simplify dependency management, all modules of JUnit Platform, Jupiter, and Vintage now use the same version number: 6.0.0
.
See the User Guide for a list of all artifacts.
-
junit-platform-jfr
(now included injunit-platform-launcher
, see User Guide) -
junit-platform-runner
(without replacement) -
junit-platform-suite-commons
(now integrated intojunit-platform-suite
)
Please refer to the release notes for a list of all removed APIs.
Starting with version 6.0.0, JUnit has adopted JSpecify. Its annotations are used to mark which of the types used in the API are nullable. JSpecify is supported in IDEs such as IntelliJ IDEA so you may notice new warnings when programming against JUnit's APIs. To check nullability during your build, we recommend using Error Prone and NullAway.
Due to the adoption of JSpecify, the ExtensionContext.Store
API was revised.
Jupiter extension implementations should be changed to call the new computeIfAbsent
family of methods rather than the now deprecated getOrComputeIfAbsent
ones.
store.getOrComputeIfAbsent(MyType.class); // <1> returns MyType
store.getOrComputeIfAbsent("key", key -> new MyType()); // <2> returns @Nullable Object
store.getOrComputeIfAbsent("key", key -> new MyType(), MyType.class); // <3> returns @Nullable MyType
store.computeIfAbsent(MyType.class); // <1> returns MyType
store.computeIfAbsent("key", key -> new MyType()); // <2> returns Object
store.computeIfAbsent("key", key -> new MyType(), MyType.class); // <3> returns MyType
In order to support cancellation of a running test execution, the existing execute
methods of the Launcher
API have been deprecated in favor of the new execute(LauncherExecutionRequest)
method.
Please refer to the User Guide for additional examples.
launcher.execute(testPlan, testExecutionListener1, ..., testExecutionListenerN);
launcher.execute(LauncherExecutionRequestBuilder.request(testPlan)
.listeners(testExecutionListener1, ..., testExecutionListenerN)
.build());
LauncherDiscoveryRequest discoveryRequest = LauncherDiscoveryRequestBuilder.request()
.selectors(...)
.filters(...)
.build();
launcher.execute(discoveryRequest, testExecutionListener1, ..., testExecutionListenerN);
LauncherDiscoveryRequest discoveryRequest = LauncherDiscoveryRequestBuilder.request()
.selectors(...)
.filters(...)
.build();
LauncherExecutionRequest executionRequest = LauncherExecutionRequestBuilder.request(discoveryRequest)
.listeners(testExecutionListener1, ..., testExecutionListenerN)
.build()
launcher.execute(executionRequest);
or
LauncherExecutionRequest executionRequest = LauncherDiscoveryRequestBuilder.request()
.selectors(...)
.filters(...)
.forExecution()
.listeners(testExecutionListener1, ..., testExecutionListenerN)
.build();
launcher.execute(executionRequest);