Writing tests is essential, but writing good tests is hard. It is specially hard to write good and readable assertions.
When you use JUnit you have methods such as assertEquals or assertTrue. Both these methods work fine and do what they should do. However if the assertions get more complex they might not be as handy as assertions could be.
AssertJ is a library that gives you the possibility to write fluent assertions in your tests.
The following example implementation of unit tests show the difference between AssertJ and standard JUnit tests.
As you can see the AssertJ test tells you in much less code exactly was it does. This make such tests a lot more readable.
Besides the standard assertions AssertJ also provides a way to generate customized assertion classes. This can either be done via the command line or your build tool, such as Maven. Such a generated assertion class can look like this:
With these generated classes you can do assertions that are customized for your objects. Of course, you can implement your own assertion methods in these classes, too. An example of a test that uses the AnimalAssert class can look like this:
If you want to know more please read the docs or head over to GitHub and check out my AssertJ showcase.