org.openrewrite.java.testing.junit5.JUnit4to5Migration
Migrates JUnit 4.x tests to JUnit Jupiter.
Tags
Recipe source
GitHub , Issue Tracker , Maven Central
groupId: org.openrewrite.recipe
artifactId: rewrite-testing-frameworks
This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.
Usage
This recipe has no required configuration options. It can be activated by adding a dependency on org.openrewrite.recipe:rewrite-testing-frameworks:2.7.0
in your build file or by running a shell command (in which case no build changes are needed):
Gradle Gradle init script Maven POM Maven Command Line Moderne CLI
Add the following to your build.gradle
file:
Copy plugins {
id( "org.openrewrite.rewrite" ) version( "6.12.0" )
}
rewrite {
activeRecipe( "org.openrewrite.java.testing.junit5.JUnit4to5Migration" )
}
repositories {
mavenCentral()
}
dependencies {
rewrite( "org.openrewrite.recipe:rewrite-testing-frameworks:2.7.0" )
}
Run gradle rewriteRun
to run the recipe.
Create a file named init.gradle
in the root of your project.
Copy initscript {
repositories {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies { classpath( "org.openrewrite:plugin:6.12.0" ) }
}
rootProject {
plugins . apply( org.openrewrite.gradle.RewritePlugin )
dependencies {
rewrite( "org.openrewrite.recipe:rewrite-testing-frameworks:2.7.0" )
}
rewrite {
activeRecipe( "org.openrewrite.java.testing.junit5.JUnit4to5Migration" )
}
afterEvaluate {
if (repositories . isEmpty()) {
repositories {
mavenCentral()
}
}
}
}
Run gradle --init-script init.gradle rewriteRun
to run the recipe.
Add the following to your pom.xml
file:
Copy < project >
< build >
< plugins >
< plugin >
< groupId >org.openrewrite.maven</ groupId >
< artifactId >rewrite-maven-plugin</ artifactId >
< version >5.29.0</ version >
< configuration >
< activeRecipes >
< recipe >org.openrewrite.java.testing.junit5.JUnit4to5Migration</ recipe >
</ activeRecipes >
</ configuration >
< dependencies >
< dependency >
< groupId >org.openrewrite.recipe</ groupId >
< artifactId >rewrite-testing-frameworks</ artifactId >
< version >2.7.0</ version >
</ dependency >
</ dependencies >
</ plugin >
</ plugins >
</ build >
</ project >
Run mvn rewrite:run
to run the recipe.
Copy mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.junit5.JUnit4to5Migration
You will need to have configured the Moderne CLI on your machine before you can run the following command.
Copy mod run . --recipe JUnit4to5Migration
Definition
Recipe List Yaml Recipe List
Remove Maven plugin dependency
pluginGroupId: org.apache.maven.plugins
pluginArtifactId: maven-surefire-plugin
groupId: org.apache.maven.surefire
artifactId: surefire-junit*
Change method name
methodPattern: org.junit.Assert assertEquals(.., Object[], Object[])
newMethodName: assertArrayEquals
Remove exclusion
groupId: org.testcontainers
artifactId: testcontainers
exclusionArtifactId: junit
Remove exclusion
groupId: org.springframework.boot
artifactId: spring-boot-testcontainers
exclusionArtifactId: junit
Copy ---
type : specs.openrewrite.org/v1beta/recipe
name : org.openrewrite.java.testing.junit5.JUnit4to5Migration
displayName : JUnit Jupiter migration from JUnit 4.x
description : Migrates JUnit 4.x tests to JUnit Jupiter.
tags :
- junit
- testing
recipeList :
- org.openrewrite.java.testing.junit5.UseWiremockExtension
- org.openrewrite.java.testing.junit5.IgnoreToDisabled
- org.openrewrite.java.testing.junit5.ThrowingRunnableToExecutable
- org.openrewrite.java.testing.junit5.RemoveObsoleteRunners :
obsoleteRunners : [ org.junit.runners.JUnit4 , org.junit.runners.BlockJUnit4ClassRunner ]
- org.openrewrite.maven.RemovePluginDependency :
pluginGroupId : org.apache.maven.plugins
pluginArtifactId : maven-surefire-plugin
groupId : org.apache.maven.surefire
artifactId : surefire-junit*
- org.openrewrite.java.testing.junit5.UseHamcrestAssertThat
- org.openrewrite.java.testing.junit5.MigrateAssumptions
- org.openrewrite.java.testing.junit5.UseMockitoExtension
- org.openrewrite.java.testing.junit5.UseTestMethodOrder
- org.openrewrite.java.testing.junit5.MigrateJUnitTestCase
- org.openrewrite.java.ChangeMethodName :
methodPattern : org.junit.Assert assertEquals(.., Object[], Object[])
newMethodName : assertArrayEquals
- org.openrewrite.java.testing.junit5.AssertToAssertions
- org.openrewrite.java.testing.junit5.CategoryToTag
- org.openrewrite.java.testing.junit5.CleanupJUnitImports
- org.openrewrite.java.testing.junit5.TemporaryFolderToTempDir
- org.openrewrite.java.testing.junit5.TempDirNonFinal
- org.openrewrite.java.testing.junit5.TestRuleToTestInfo
- org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations
- org.openrewrite.java.testing.junit5.UpdateTestAnnotation
- org.openrewrite.java.testing.junit5.AddMissingTestBeforeAfterAnnotations
- org.openrewrite.java.testing.junit5.ParameterizedRunnerToParameterized
- org.openrewrite.java.testing.junit5.JUnitParamsRunnerToParameterized
- org.openrewrite.java.testing.junit5.ExpectedExceptionToAssertThrows
- org.openrewrite.java.testing.junit5.UpdateMockWebServer
- org.openrewrite.java.testing.junit5.VertxUnitToVertxJunit5
- org.openrewrite.java.testing.junit5.EnclosedToNested
- org.openrewrite.java.testing.junit5.AddMissingNested
- org.openrewrite.java.testing.hamcrest.AddHamcrestIfUsed
- org.openrewrite.java.testing.junit5.UseXMLUnitLegacy
- org.openrewrite.java.dependencies.RemoveDependency :
groupId : junit
artifactId : junit
- org.openrewrite.maven.ExcludeDependency :
groupId : junit
artifactId : junit
- org.openrewrite.maven.RemoveExclusion :
groupId : org.testcontainers
artifactId : testcontainers
exclusionGroupId : junit
exclusionArtifactId : junit
- org.openrewrite.maven.RemoveExclusion :
groupId : org.springframework.boot
artifactId : spring-boot-testcontainers
exclusionGroupId : junit
exclusionArtifactId : junit
- org.openrewrite.java.dependencies.RemoveDependency :
groupId : org.junit.vintage
artifactId : junit-vintage-engine
- org.openrewrite.maven.ExcludeDependency :
groupId : org.junit.vintage
artifactId : junit-vintage-engine
- org.openrewrite.java.testing.junit5.AddJupiterDependencies
- org.openrewrite.java.dependencies.AddDependency :
groupId : org.junit.jupiter
artifactId : junit-jupiter-params
version : 5.x
onlyIfUsing : org.junit.jupiter.params.ParameterizedTest
scope : test
acceptTransitive : true
- org.openrewrite.java.dependencies.UpgradeDependencyVersion :
groupId : org.mockito
artifactId : *
newVersion : 3.x
overrideManagedVersion : false
- org.openrewrite.java.dependencies.AddDependency :
groupId : org.mockito
artifactId : mockito-junit-jupiter
version : 3.x
onlyIfUsing : org.mockito..*
scope : test
acceptTransitive : true
- org.openrewrite.maven.UpgradePluginVersion :
groupId : org.apache.maven.plugins
artifactId : maven-surefire-plugin
newVersion : 3.1.x
- org.openrewrite.maven.UpgradePluginVersion :
groupId : org.apache.maven.plugins
artifactId : maven-failsafe-plugin
newVersion : 3.1.x
- org.openrewrite.java.testing.junit5.GradleUseJunitJupiter
See how this recipe works across multiple open-source repositories
The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Contributors
Patrick Way, Sam Snyder , Jonathan Schneider , Knut Wannheden , Patrick , Greg Adams , Jonathan Schnéider , Tracey Yoshima , Greg Adams , Tim te Beek , magicwerk , Nick McKinney , Tyler Van Gorder, Tim te Beek , Sofia Britto Schwartz , Aaron Gershman , Michael Keppler , John Burns, traceyyoshima , Scott Jungling , Tim te Beek , Peter Puškár, Joan Viladrosa , Kun Li , Kyle Scully , Simon Verhoeven , Mike Solomon