In this tutorial, we'll use OpenRewrite to perform an automated migration from JUnit Asserts to AssertJ. AssertJ is a Java library that provides a rich set of assertions and truly helpful error messages, improves test code readability, and is designed to be super easy to use within your favorite IDE.
Example Configuration
The migrate to AssertJ recipe can be applied by adding OpenRewrite's plugin to your project and including a dependency on rewrite-testing-frameworks:
plugins { id("java") id("org.openrewrite.rewrite") version("6.12.0") } rewrite { activeRecipe("org.openrewrite.java.testing.assertj.JUnitToAssertj") } repositories { mavenCentral() // rewrite-spring is published to Maven Central } dependencies { rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:2.10.0")) rewrite("org.openrewrite.recipe:rewrite-testing-frameworks")// Other project dependencies }
At this point, you're ready to execute the migration by running mvn rewrite:run or gradlew rewriteRun. After running the migration you can inspect the results with git diff (or equivalent), manually fix anything that wasn't able to be migrated automatically, and commit the results.
Before and After
For the full list of changes, this recipe will make, see its reference page.