A quick demo application to show various assertion (anti-)patterns, and how to improve those with OpenRewrite recipes.
A bit of a rant on bad testing practices seen over the years.
- No tests at all.
- Code coverage tests
- Plain
assert - AssertEquals list size
- AssertTrue list contains
- Failure message argument order
- Try catch and fail
- AssertThrows catch early
Beyond just bad practices, there are also just outdated practices.
A few examples of my favorite features of AssertJ.
A quick command to improve the above tests by adopting AssertJ.
mvn rewrite:run -Drewrite.activeRecipes=com.github.timtebeek.BetterAssertionsAssertJ themselves also have a helpful, if incomplete example repository.
- https://github.com/assertj/assertj-examples/
- https://github.com/assertj/assertj-examples/commit/72c339f0f72fd4a6e903c25af2d3f093702f3e4c
Finally, MockMvc tests can now use AssertJ instead of Hamcrest for assertions.