AssertJ
Cheat Sheet
This is a draft of a “cheat sheet” for AssertJ, a fluent assertions library for use with Java and JUnit.
What’s in the Cheat Sheet?
Asserting that the contents of a List, Set, and other Iterables, is where AssertJ’s contains
methods come in really handy. I often get confused with variations of contains
, such as containsOnly
and containsExactly
, so I created some examples of tests using these variations:
contains
containsOnly
containsOnlyOnce
containsExactly
containsExactlyInAnyOrder
Eventually the cheat sheet will cover more of the methods that I commonly use in my tests. If you want to stay updated, subscribe to my email list at the bottom of this page. If you have suggestions for which assertions of AssertJ to add, join my Discord, email me (ted@
this domain) or message me on Twitter or Mastodon.
Download the Cheat Sheet
Click here for the PDF of the cheat sheet.