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, and junit-jupiter-params dependencies 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-launcher dependency to Gradle’s testRuntimeOnly configuration, 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, and junit-platform-suite-commons.

  • Remove the retired org.junit.jupiter:junit-jupiter-migrationsupport module.

  • Rename MethodOrderer.Alphanumeric to MethodOrderer.MethodName.

  • Move JUnit Jupiter Constants from org.junit.jupiter.engine to org.junit.jupiter.api.

  • Remove the retired @UseTechnicalNames annotation from suite declarations.

  • Remove the retired lineSeparator attribute from @CsvFileSource annotations.

  • Delete the retired JUnit Platform configuration properties junit.jupiter.tempdir.scope and junit.jupiter.params.arguments.conversion.locale.format.

  • Rename Executions.started() to Executions.finished() in the JUnit Platform Test Kit (the only invariant the legacy method actually preserved).

  • Rename getOrComputeIfAbsent to computeIfAbsent on ExtensionContext.Store and NamespacedHierarchicalStore.

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