My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages
Links

EqualsVerifier

EqualsVerifier can be used in Java unit tests to verify whether the contract for the equals and hashCode methods in a class is met. The contracts are described in the Javadoc comments for the java.lang.Object class.

What's new?

Check out the Changelog!

Quick start

  • Get EqualsVerifier.
    • Maven users: EqualsVerifier is available from Maven Central. The groupId is nl.jqno.equalsverifier and the artifactId is equalsverifier. Make sure to use the latest version, and put it in the test scope.
    • Maven users who want to use version 1.0.2 or earlier: click here. Note that this method is now deprecated; use at your own risk.
    • ANT users: make sure the following jars are on the classpath:
  • Use, as follows, in your unit test:
  • @Test
    public void equalsContract() {
        EqualsVerifier.forClass(My.class).verify();
    }
  • Or, if you prefer to use a getClass() check instead of an instanceof check in the body of your equals method:
  • @Test
    public void equalsContract() {
        EqualsVerifier.forClass(My.class)
                .usingGetClass()
                .verify();
    }
  • With some warnings suppressed:
  • @Test
    public void equalsContract() {
        EqualsVerifier.forClass(My.class)
                .suppress(Warning.NONFINAL_FIELDS, Warning.NULL_FIELDS)
                .verify();
    }

When EqualsVerifier detects a problem, it will explain what it thinks is wrong. In some cases (mostly when it needs more information), it will say what to do to fix the problem.

Help, I don't understand an error message!

Never fear, help is here.

Documentation

Powered by Google Project Hosting