JUnit Jupiter migration from JUnit 4.x
Recipe ID
org.openrewrite.java.testing.junit5.JUnit4to5MigrationArtifact
org.openrewrite.recipe:rewrite-testing-frameworksMigrates JUnit 4.x tests to JUnit Jupiter.
Usage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.java.testing.junit5.JUnit4to5MigrationIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-testing-frameworks:3.43.0Definition
This recipe runs the following recipes in order.
- Migrate JUnit 4 environmentVariables rule to JUnit 5 system stubs extension
org.openrewrite.java.testing.junit5.EnvironmentVariables - Use wiremock extension
org.openrewrite.java.testing.junit5.UseWiremockExtension - Use JUnit Jupiter
@Disabledorg.openrewrite.java.testing.junit5.IgnoreToDisabled - Use JUnit Jupiter
Executableorg.openrewrite.java.testing.junit5.ThrowingRunnableToExecutable - Remove JUnit 4
@RunWithannotations that do not require an@ExtendsWithreplacementorg.openrewrite.java.testing.junit5.RemoveObsoleteRunners - Remove Maven plugin dependency
org.openrewrite.maven.RemovePluginDependency - Upgrade Surefire Plugin
org.openrewrite.java.testing.junit5.UpgradeSurefirePlugin - Add Hamcrest JUnit dependency
org.openrewrite.java.testing.junit5.AddHamcrestJUnitDependency - Use
MatcherAssert#assertThat(..)org.openrewrite.java.testing.junit5.UseHamcrestAssertThat - Use
Assertions#assume*(..)and Hamcrest'sMatcherAssume#assume*(..)org.openrewrite.java.testing.junit5.MigrateAssumptions - Migrate from JUnit 4
@FixedMethodOrderto JUnit 5@TestMethodOrderorg.openrewrite.java.testing.junit5.UseTestMethodOrder - Migrate JUnit 4
TestCaseto JUnit Jupiterorg.openrewrite.java.testing.junit5.MigrateJUnitTestCase - Change method name
org.openrewrite.java.ChangeMethodName - JUnit 4
AssertTo JUnit JupiterAssertionsorg.openrewrite.java.testing.junit5.AssertToAssertions - JUnit 4
@Categoryto JUnit Jupiter@Tagorg.openrewrite.java.testing.junit5.CategoryToTag - Migrate JUnit 4 assertion failure exceptions to JUnit Jupiter
org.openrewrite.java.testing.junit5.MigrateAssertionFailedError - Cleanup JUnit imports
org.openrewrite.java.testing.junit5.CleanupJUnitImports - Use JUnit Jupiter
@TempDirorg.openrewrite.java.testing.junit5.TemporaryFolderToTempDir - Make
@TempDirfields non finalorg.openrewrite.java.testing.junit5.TempDirNonFinal - JUnit TestName @Rule to JUnit Jupiter TestInfo
org.openrewrite.java.testing.junit5.TestRuleToTestInfo - Migrate JUnit 4 lifecycle annotations to JUnit Jupiter
org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations - Migrate JUnit 4
@Testannotations to JUnit 5org.openrewrite.java.testing.junit5.UpdateTestAnnotation - JUnit 4
@Rule Timeoutto JUnit Jupiter'sTimeoutorg.openrewrite.java.testing.junit5.TimeoutRuleToClassAnnotation - Add missing
@BeforeEach,@AfterEach,@Testto overriding methodsorg.openrewrite.java.testing.junit5.AddMissingTestBeforeAfterAnnotations - JUnit 4
@RunWith(Parameterized.class)to JUnit Jupiter parameterized testsorg.openrewrite.java.testing.junit5.ParameterizedRunnerToParameterized - Pragmatists
@RunWith(JUnitParamsRunner.class)to JUnit Jupiter@Parameterizedtestsorg.openrewrite.java.testing.junit5.JUnitParamsRunnerToParameterized - JUnit 4
ExpectedExceptionTo JUnit Jupiter'sassertThrows()org.openrewrite.java.testing.junit5.ExpectedExceptionToAssertThrows - OkHttp 3.x
MockWebServer@RuleTo 4.xMockWebServerorg.openrewrite.java.testing.junit5.UpdateMockWebServer - Use Vert.x JUnit 5 Extension
org.openrewrite.java.testing.junit5.VertxUnitToVertxJunit5 - JUnit 4
@RunWith(Enclosed.class)to JUnit Jupiter@Nestedorg.openrewrite.java.testing.junit5.EnclosedToNested - JUnit 5 inner test classes should be annotated with
@Nestedorg.openrewrite.java.testing.junit5.AddMissingNested - Use OkHttp 3 MockWebServer for JUnit 5
org.openrewrite.java.testing.junit5.UpgradeOkHttpMockWebServer - Use Mockito JUnit Jupiter extension
org.openrewrite.java.testing.junit5.UseMockitoExtension - Add
org.hamcrest:hamcrestif it is usedorg.openrewrite.java.testing.hamcrest.AddHamcrestIfUsed - Use XMLUnit Legacy for JUnit 5
org.openrewrite.java.testing.junit5.UseXMLUnitLegacy - Remove a Gradle or Maven dependency
org.openrewrite.java.dependencies.RemoveDependency - Remove Maven managed dependency
org.openrewrite.maven.RemoveManagedDependency - Exclude JUnit 4, unless Testcontainers is used
org.openrewrite.java.testing.junit5.ExcludeJUnit4UnlessUsingTestcontainers - Remove a Gradle or Maven dependency
org.openrewrite.java.dependencies.RemoveDependency - Remove Maven managed dependency
org.openrewrite.maven.RemoveManagedDependency - Exclude Maven dependency
org.openrewrite.maven.ExcludeDependency - Add JUnit Jupiter dependencies
org.openrewrite.java.testing.junit5.AddJupiterDependencies - Add Gradle or Maven dependency
org.openrewrite.java.dependencies.AddDependency - Upgrade Maven plugin version
org.openrewrite.maven.UpgradePluginVersion - Upgrade Maven plugin version
org.openrewrite.maven.UpgradePluginVersion - Gradle
Testuse JUnit Jupiterorg.openrewrite.java.testing.junit5.GradleUseJunitJupiter - Change type
org.openrewrite.java.ChangeType - Use Arquillian JUnit 5 Extension
org.openrewrite.java.testing.arquillian.ArquillianJUnit4ToArquillianJUnit5 - Use Byteman JUnit 5 dependency
org.openrewrite.java.testing.byteman.BytemanJUnit4ToBytemanJUnit5 - Migrate rider-spring (JUnit4) to rider-junit5 (JUnit5)
org.openrewrite.java.testing.dbrider.MigrateDbRiderSpringToDbRiderJUnit5 - Handle the usage of ExternalResourceRule fields using @ExtendWith(ExternalResourceSupport.class)
org.openrewrite.java.testing.junit5.HandleExternalResourceRules
Data tables
Structured output this recipe can produce.
- Maven metadata failuresAttempts to resolve maven metadata that failed.
org.openrewrite.maven.table.MavenMetadataFailures - Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats