Skip to content

jqno/equalsverifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EqualsVerifier

Build Status Issue resolution Apache License 2.0 Maven Central Javadoc

EqualsVerifier can be used in Java unit tests to verify whether the contract for the equals and hashCode methods in a class is met.

Getting Started

EqualsVerifier's Maven coordinates are:

<dependency>
    <groupId>nl.jqno.equalsverifier</groupId>
    <artifactId>equalsverifier</artifactId>
    <version>4.0.7</version>
    <scope>test</scope>
</dependency>

(Note that there's also a 'fat' jar with no transitive dependencies with artifactId equalsverifier-nodep.)

Now you can write a test:

import nl.jqno.equalsverifier.*;

@Test
public void equalsContract() {
    EqualsVerifier.forClass(Foo.class).verify();
}

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:

import nl.jqno.equalsverifier.*;

@Test
public void equalsContract() {
    EqualsVerifier.simple().forClass(Foo.class).verify();
}

This way, EqualsVerifier will throw less errors at you. However, it's usually better to just fix the errors: EqualsVerifier throws them for a reason!

Prefer to watch a short video?

EqualsVerifier getting started video by Tom Cools

Video by Tom Cools

Documentation

For more documentation, see:

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.

🌈🧑🏻‍🤝‍🧑🏾🌍

Contribution

Pull requests are welcome! If you plan to open one, please also register an issue or start a discussion, so we can discuss it first. It would be a shame to put in a lot of work on something that isn't a good fit for the project. Also, I can help you by giving pointers on where to find certain things.

Disclaimer

Copyright 2009-2025 Jan Ouwens

About

EqualsVerifier can be used in Java unit tests to verify whether the contract for the equals and hashCode methods is met.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 35