Files
gh-openrewrite-rewrite-docs…/skills/writing-openrewrite-recipes/references/recipes-testing-common.csv
2025-11-30 08:45:33 +08:00

62 lines
13 KiB
CSV
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Fully Qualified Recipe Name,Recipe Name,Description
org.openrewrite.java.spring.test.SpringRulesToJUnitExtension,Replace `SpringClassRule` and `SpringMethodRule` with JUnit 5 `SpringExtension`,Replace JUnit 4's `SpringClassRule` and `SpringMethodRule` with JUnit 5's `SpringExtension` or rely on an existing `@SpringBootTest`.
org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration,Migrate Spring Boot 2.x projects to JUnit 5 from JUnit 4,This recipe will migrate a Spring Boot application's tests from JUnit 4 to JUnit 5. This spring-specific migration includes conversion of Spring Test runners to Spring Test extensions and awareness of the composable Spring Test annotations.
org.openrewrite.java.testing.assertj.AdoptAssertJDurationAssertions,Adopt AssertJ Duration assertions,Adopt AssertJ `DurationAssert` assertions for more expressive messages.
org.openrewrite.java.testing.assertj.CollapseConsecutiveAssertThatStatements,Collapse consecutive `assertThat` statements,Collapse consecutive `assertThat` statements into single `assertThat` chained statement. This recipe ignores `assertThat` statements that have method invocation as parameter.
org.openrewrite.java.testing.assertj.IsEqualToIgnoringMillisToIsCloseToRecipe,Replace `AbstractDateAssert#isEqualToIgnoringMillis(java.util.Date)` by `by isCloseTo(Date long)`,`isEqualToIgnoringMillis()` is deprecated in favor of `isCloseTo()`.
org.openrewrite.java.testing.assertj.JUnitAssertArrayEqualsToAssertThat,JUnit `assertArrayEquals` to assertJ,Convert JUnit-style `assertArrayEquals()` to AssertJ's `assertThat().contains()` equivalents.
org.openrewrite.java.testing.assertj.JUnitAssertEqualsToAssertThat,JUnit `assertEquals` to AssertJ,Convert JUnit-style `assertEquals()` to AssertJ's `assertThat().isEqualTo()`.
org.openrewrite.java.testing.assertj.JUnitAssertFalseToAssertThat,JUnit `assertFalse` to AssertJ,Convert JUnit-style `assertFalse()` to AssertJ's `assertThat().isFalse()`.
org.openrewrite.java.testing.assertj.JUnitAssertInstanceOfToAssertThat,JUnit `assertInstanceOf` to AssertJ,Convert JUnit-style `assertInstanceOf()` to AssertJ's `assertThat().isInstanceOf()`.
org.openrewrite.java.testing.assertj.JUnitAssertNotEqualsToAssertThat,JUnit `assertNotEquals` to AssertJ,Convert JUnit-style `assertNotEquals()` to AssertJ's `assertThat().isNotEqualTo()`.
org.openrewrite.java.testing.assertj.JUnitAssertNotNullToAssertThat,JUnit `assertNotNull` to AssertJ,Convert JUnit-style `assertNotNull()` to AssertJ's `assertThat().isNotNull()`.
org.openrewrite.java.testing.assertj.JUnitAssertNullToAssertThat,JUnit `assertNull` to AssertJ,Convert JUnit-style `assertNull()` to AssertJ's `assertThat().isNull()`.
org.openrewrite.java.testing.assertj.JUnitAssertSameToAssertThat,JUnit `assertSame` to AssertJ,Convert JUnit-style `assertSame()` to AssertJ's `assertThat().isSameAs()`.
org.openrewrite.java.testing.assertj.JUnitAssertThrowsToAssertExceptionType,JUnit AssertThrows to AssertJ exceptionType,Convert `JUnit#AssertThrows` to `AssertJ#assertThatExceptionOfType` to allow for chained assertions on the thrown exception.
org.openrewrite.java.testing.assertj.JUnitAssertTrueToAssertThat,JUnit `assertTrue` to AssertJ,Convert JUnit-style `assertTrue()` to AssertJ's `assertThat().isTrue()`.
org.openrewrite.java.testing.assertj.JUnitFailToAssertJFail,JUnit fail to AssertJ,Convert JUnit-style `fail()` to AssertJ's `fail()`.
org.openrewrite.java.testing.assertj.JUnitTryFailToAssertThatThrownBy,Convert try-catch-fail blocks to AssertJ's assertThatThrownBy,Replace try-catch blocks where the try block ends with a `fail()` statement and the catch block optionally contains assertions with AssertJ's `assertThatThrownBy()`.
org.openrewrite.java.testing.assertj.SimplifyAssertJAssertion,Simplify AssertJ assertions with literal arguments,Simplify AssertJ assertions by replacing them with more expressive dedicated assertions.
org.openrewrite.java.testing.assertj.SimplifyChainedAssertJAssertion,Simplify AssertJ chained assertions,Many AssertJ chained assertions have dedicated assertions that function the same. It is best to use the dedicated assertions.
org.openrewrite.java.testing.assertj.SimplifyHasSizeAssertion,Simplify AssertJ assertions with `hasSize` argument,Simplify AssertJ assertions by replacing `hasSize` with `hasSameSizeAs` dedicated assertions.
org.openrewrite.java.testing.assertj.SimplifyRedundantAssertJChains,Simplify redundant AssertJ assertion chains,Removes redundant AssertJ assertions when chained methods already provide the same or stronger guarantees.
org.openrewrite.java.testing.cleanup.AssertEqualsBooleanToAssertBoolean,Replace JUnit `assertEquals(false <boolean>)` to `assertFalse(<boolean>)` / `assertTrue(<boolean>)`,Using `assertFalse` or `assertTrue` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertEqualsNullToAssertNull,`assertEquals(a null)` to `assertNull(a)`,Using `assertNull(a)` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertFalseEqualsToAssertNotEquals,Replace JUnit `assertFalse(a.equals(b))` to `assertNotEquals(ab)`,Using `assertNotEquals(ab)` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertFalseNegationToAssertTrue,Replace JUnit `assertFalse(!<boolean>)` to `assertTrue(<boolean>)`,Using `assertTrue` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertFalseNullToAssertNotNull,Replace JUnit `assertFalse(a == null)` to `assertNotNull(a)`,Using `assertNotNull(a)` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertLiteralBooleanRemovedRecipe,Remove JUnit `assertTrue(true)` and `assertFalse(false)`,These assertions are redundant and do not provide any value. They can be safely removed.
org.openrewrite.java.testing.cleanup.AssertLiteralBooleanToFailRecipes,"Replace JUnit `assertTrue(false ""reason"")` and `assertFalse(true ""reason"")` with `fail(""reason"")`",Using fail is more direct and clear.
org.openrewrite.java.testing.cleanup.AssertNotEqualsBooleanToAssertBoolean,Replace JUnit `assertNotEquals(false <boolean>)` to `assertFalse(<boolean>)` / `assertTrue(<boolean>)`,Using `assertFalse` or `assertTrue` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertTrueComparisonToAssertEquals,Junit `assertTrue(a == b)` to `assertEquals(ab)`,Using `assertEquals(ab)` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertTrueEqualsToAssertEquals,Replace JUnit `assertTrue(a.equals(b))` to `assertEquals(ab)`,Using `assertEquals(ab)` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertTrueNegationToAssertFalse,Replace JUnit `assertTrue(!<boolean>)` to `assertFalse(<boolean>)`,Using `assertFalse` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertTrueNullToAssertNull,Replace JUnit `assertTrue(a == null)` to `assertNull(a)`,Using `assertNull(a)` is simpler and more clear.
org.openrewrite.java.testing.cleanup.AssertionsArgumentOrder,Assertion arguments should be passed in the correct order,Assertions such as `org.junit.Assert.assertEquals` expect the first argument to be the expected value and the second argument to be the actual value; for `org.testng.Assert` its the other way around. This recipe detects `J.Literal` `J.NewArray` and `java.util.Iterable` arguments swapping them if necessary so that the error messages won't be confusing.
org.openrewrite.java.testing.cleanup.RemoveEmptyTests,Remove empty tests without comments,Removes empty methods with a `@Test` annotation if the body does not have comments.
org.openrewrite.java.testing.cleanup.RemoveTestPrefix,Remove `test` prefix from JUnit 5 tests,Remove `test` from methods with `@Test` `@ParameterizedTest` `@RepeatedTest` or `@TestFactory`. They no longer have to prefix test to be usable by JUnit 5.
org.openrewrite.java.testing.cleanup.SimplifyTestThrows,Simplify `throws` statements of tests,Replace all thrown exception classes of test method signatures by `Exception`.
org.openrewrite.java.testing.cleanup.TestMethodsShouldBeVoid,Test methods should have void return type,Test methods annotated with `@Test` `@ParameterizedTest` `@RepeatedTest` `@TestTemplate` should have `void` return type. Non-void return types can cause test discovery issues and warnings as of JUnit 5.13+. This recipe changes the return type to `void` and removes `return` statements.
org.openrewrite.java.testing.cleanup.TestsShouldIncludeAssertions,Include an assertion in tests,For tests not having any assertions wrap the statements with JUnit Jupiter's `Assertions#assertDoesNotThrow(..)`.
org.openrewrite.java.testing.dbrider.ExecutionListenerToDbRiderAnnotation,Migrate the `DBRiderTestExecutionListener` to the `@DBRider` annotation,Migrate the `DBRiderTestExecutionListener` to the `@DBRider` annotation. This recipe is useful when migrating from JUnit 4 `dbrider-spring` to JUnit 5 `dbrider-junit5`.
org.openrewrite.java.testing.easymock.EasyMockVerifyToMockitoVerify,Replace EasyMock `verify` calls with Mockito `verify` calls,Replace `EasyMock.verify(dependency)` with individual `Mockito.verify(dependency).method()` calls based on expected methods.
org.openrewrite.java.testing.easymock.RemoveExtendsEasyMockSupport,Migrate Test classes that extend `org.easymock.EasyMockSupport` to use Mockito,Modify test classes by removing extends EasyMockSupport and replacing EasyMock methods with Mockito equivalents.
org.openrewrite.java.testing.hamcrest.AssertThatBooleanToAssertJ,Migrate Hamcrest `assertThat(boolean Matcher)` to AssertJ,Replace Hamcrest `assertThat(String boolean)` with AssertJ `assertThat(boolean).as(String).isTrue()`.
org.openrewrite.java.testing.hamcrest.HamcrestInstanceOfToJUnit5,Migrate from Hamcrest `instanceOf` matcher to JUnit 5,Migrate from Hamcrest `instanceOf` and `isA` matcher to JUnit5 `assertInstanceOf` assertion.
org.openrewrite.java.testing.hamcrest.HamcrestIsMatcherToAssertJ,Migrate Hamcrest `is(Object)` to AssertJ,Migrate Hamcrest `is(Object)` to AssertJ `Assertions.assertThat(..)`.
org.openrewrite.java.testing.hamcrest.HamcrestMatcherToAssertJ,Migrate from Hamcrest `Matcher` to AssertJ,Migrate from Hamcrest `Matcher` to AssertJ assertions.
org.openrewrite.java.testing.hamcrest.HamcrestMatcherToJUnit5,Migrate from Hamcrest `Matcher` to JUnit 5,Migrate from Hamcrest `Matcher` to JUnit 5 assertions.
org.openrewrite.java.testing.hamcrest.HamcrestNotMatcherToAssertJ,Migrate Hamcrest `not(Matcher)` to AssertJ,Migrate from Hamcrest `not(Matcher)` to AssertJ assertions.
org.openrewrite.java.testing.hamcrest.HamcrestOfMatchersToAssertJ,Migrate `anyOf` Hamcrest Matcher to AssertJ,Migrate the `anyOf` Hamcrest Matcher to AssertJ's `satisfiesAnyOf` assertion.
org.openrewrite.java.testing.jmockit.JMockitAnnotatedArgumentToMockito,Convert JMockit `@Mocked` and `@Injectable` annotated arguments,Convert JMockit `@Mocked` and `@Injectable` annotated arguments into Mockito statements.
org.openrewrite.java.testing.jmockit.JMockitBlockToMockito,Rewrite JMockit Expectations NonStrictExpectations Verifications VerificationsInOrder FullVerifications,Rewrites JMockit `Expectations NonStrictExpectations Verifications VerificationsInOrder FullVerifications` blocks to Mockito statements.
org.openrewrite.java.testing.jmockit.JMockitMockUpToMockito,Rewrite JMockit MockUp to Mockito statements,Rewrites JMockit `MockUp` blocks to Mockito statements. This recipe will not rewrite private methods in MockUp.
org.openrewrite.java.testing.junit5.AddMissingNested,JUnit 5 inner test classes should be annotated with `@Nested`,Adds `@Nested` to inner classes that contain JUnit 5 tests.
org.openrewrite.java.testing.junit5.AddMissingTestBeforeAfterAnnotations,Add missing `@BeforeEach` `@AfterEach` `@Test` to overriding methods,Adds `@BeforeEach` `@AfterEach` `@Test` to methods overriding superclass methods if the annotations are present on the superclass method.
org.openrewrite.java.testing.junit5.AddParameterizedTestAnnotation,Add missing `@ParameterizedTest` annotation when `@ValueSource` is used or replace `@Test` with `@ParameterizedTest`,Add missing `@ParameterizedTest` annotation when `@ValueSource` is used or replace `@Test` with `@ParameterizedTest`.
org.openrewrite.java.testing.junit5.AssertThrowsOnLastStatement,Applies JUnit 5 `assertThrows` on last statement in lambda block only,Applies JUnit 5 `assertThrows` on last statement in lambda block only. In rare cases may cause compilation errors if the lambda uses effectively non final variables. In some cases tests might fail if earlier statements in the lambda block throw exceptions.
org.openrewrite.java.testing.junit5.AssertToAssertions,JUnit 4 `Assert` To JUnit Jupiter `Assertions`,Change JUnit 4's `org.junit.Assert` into JUnit Jupiter's `org.junit.jupiter.api.Assertions`.
org.openrewrite.java.testing.junit5.AssertTrueInstanceofToAssertInstanceOf,assertTrue(x instanceof y) to assertInstanceOf(y.class x),Migration of JUnit4 (or potentially JUnit5) test case in form of assertTrue(x instanceof y) to assertInstanceOf(y.class x).
org.openrewrite.java.testing.junit5.CleanupJUnitImports,Cleanup JUnit imports,Removes unused `org.junit` import symbols.
org.openrewrite.java.testing.junit5.EnvironmentVariables,Migrate JUnit 4 environmentVariables rule to JUnit 5 system stubs extension,Replaces usage of the JUnit 4 `@Rule EnvironmentVariables` with the JUnit 5-compatible `SystemStubsExtension` and `@SystemStub EnvironmentVariables` from the System Stubs library.