Upgrading to JUnit 6.0 - junit-team/junit-framework GitHub Wiki
This page provides guidance on upgrading from JUnit 5.x.y to 6.0.0
This is currently a work in progress.
Overview
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.
New Baselines
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.
New Versioning Scheme
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.
Removed Modules
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
)
Removed APIs
Please refer to the release notes for a list of all removed APIs.
Null Safety
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.
Deprecated APIs
JUnit Jupiter
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.
5.x.y
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
6.0.0
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