Skip to content

A quick demo application to show various assertion (anti-)patterns, and how to improve those with OpenRewrite recipes.

Notifications You must be signed in to change notification settings

timtebeek/better-assertions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Better Assertions

A quick demo application to show various assertion (anti-)patterns, and how to improve those with OpenRewrite recipes.

Bad examples

A bit of a rant on bad testing practices seen over the years.

  1. No tests at all.
  2. Code coverage tests
  3. Plain assert
  4. AssertEquals list size
  5. AssertTrue list contains
  6. Failure message argument order
  7. Try catch and fail
  8. AssertThrows catch early

Dated examples

Beyond just bad practices, there are also just outdated practices.

  1. JUnit 3
  2. JUnit 4
  3. Hamcrest
  4. JUnit Jupiter
  5. AssertJ
  6. Outdated Java in tests

Better examples

A few examples of my favorite features of AssertJ.

  1. Chained assertions
  2. Custom AssertionProvider
  3. Soft assertions
  4. Satisfies

Automatic conversion

A quick command to improve the above tests by adopting AssertJ.

mvn rewrite:run -Drewrite.activeRecipes=com.github.timtebeek.BetterAssertions

AssertJ's own examples

AssertJ themselves also have a helpful, if incomplete example repository.

  1. https://github.com/assertj/assertj-examples/
  2. https://github.com/assertj/assertj-examples/commit/72c339f0f72fd4a6e903c25af2d3f093702f3e4c

MockMvc examples

Finally, MockMvc tests can now use AssertJ instead of Hamcrest for assertions.

  1. MockMvc test with Hamcrest
  2. MockMvc test with AssertJ
  3. MockMvc test with bridge

About

A quick demo application to show various assertion (anti-)patterns, and how to improve those with OpenRewrite recipes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages