Have you ever written an
equals method, along with five screens of unit tests to test it? Or worse: not bothered to test it at all, because “the IDE generates it anyway”?
EqualsVerifier helps you. Testing
equals can be as simple as:
EqualsVerifier is an opinionated library, which means that it can be quite strict. If you feel it’s too much, you can make it more lenient:
And EqualsVerifier even gives you 100% coverage on
Don’t forget to add it to your build!
or, for a ‘fat’ jar with no transitive dependencies:
Prefer to watch a short video?
Video by Tom Cools
A note on equality
EqualsVerifier cares about bug-free equality, in Java and in real life. The place where a person happens to be born, the colour of their skin, their gender, or the person they happen to love, must not affect the way they are treated in life. If it does, that’s a bug and it should throw an error.
Don’t allow bugs in your equality.