JUnit 6
When upgrading to JUnit 6.x, refer to the JUnit 6.0 Release Notes for newly introduced APIs, deprecated APIs, and breaking changes.
The io.arconia.rewrite.testing.junit.UpgradeJUnit_6 recipe automates most of the changes introduced in JUnit 6.x. You can use it to update your project to the latest JUnit 6.x release.
The recipe will:
-
Upgrade all
org.junit.jupiter:junit-jupiter,junit-jupiter-api,junit-jupiter-engine, andjunit-jupiter-paramsdependencies to the 6.x release line. -
Upgrade the Maven Surefire and Failsafe plugins to 3.x, the minimum required for JUnit Platform compatibility.
-
Add the
org.junit.platform:junit-platform-launcherdependency to Gradle’stestRuntimeOnlyconfiguration, which is required at runtime by the JUnit 6 platform. -
Remove the JUnit Platform modules that have been retired in 6:
junit-platform-jfr,junit-platform-runner, andjunit-platform-suite-commons. -
Remove the retired
org.junit.jupiter:junit-jupiter-migrationsupportmodule. -
Rename
MethodOrderer.AlphanumerictoMethodOrderer.MethodName. -
Move JUnit Jupiter
Constantsfromorg.junit.jupiter.enginetoorg.junit.jupiter.api. -
Remove the retired
@UseTechnicalNamesannotation from suite declarations. -
Remove the retired
lineSeparatorattribute from@CsvFileSourceannotations. -
Delete the retired JUnit Platform configuration properties
junit.jupiter.tempdir.scopeandjunit.jupiter.params.arguments.conversion.locale.format. -
Rename
Executions.started()toExecutions.finished()in the JUnit Platform Test Kit (the only invariant the legacy method actually preserved). -
Rename
getOrComputeIfAbsenttocomputeIfAbsentonExtensionContext.StoreandNamespacedHierarchicalStore.
See its entry in the Recipe Catalog for the full list of recipes this upgrade applies, each with its options and a before/after example.
Run the Recipe
You can apply this recipe with any OpenRewrite-compatible tool. The tabs below show three of them: the Arconia CLI, the OpenRewrite Gradle plugin, and the OpenRewrite Maven plugin. See Running Recipes for a comparison of when to pick each one.
-
Arconia CLI
-
Gradle
-
Maven
arconia rewrite run --recipe-name io.arconia.rewrite.testing.junit.UpgradeJUnit_6
First, create an init.gradle file in your project root with the following content.
initscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("org.openrewrite:plugin:latest.release")
}
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("io.arconia.migrations:rewrite-testing:latest.release")
}
// Remove when project repositories are disabled
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
configurations.named("rewrite") {
canBeConsumed = false
}
}
Then, run the following command.
./gradlew rewriteRun \
--init-script init.gradle \
--no-parallel \
-DactiveRecipe=io.arconia.rewrite.testing.junit.UpgradeJUnit_6
You can remove the init.gradle file afterwards.
./mvnw -U org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.recipeArtifactCoordinates=io.arconia.migrations:rewrite-testing:LATEST \
-Drewrite.activeRecipes=io.arconia.rewrite.testing.junit.UpgradeJUnit_6