How to unit test equals and hashcode

H

The equals and hashcode methodes are simple to test with JQNO.

Maven dependency:

<dependency>
    <groupId>nl.jqno.equalsverifier</groupId>
    <artifactId>equalsverifier</artifactId>
    <version>1.1.3</version>
</dependency>

Jar:

http://mvnrepository.com/artifact/nl.jqno.equalsverifier/equalsverifier/1.1.3

Code:

@Test
public void testEqualsAndHashcode() {
    EqualsVerifier.forClass(ModelClassToTest.class).usingGetClass().suppress(Warning.NONFINAL_FIELDS).verify();
}

(ModelClassToTest = your class name you want to test)

Add comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Tag Cloud

Categories