EQUALSVERIFIER | Release Normal Jar framework and other tools in the Java library
EQUALSVERIFIER is a Java library to test the correctness and consistency of the Equals and HashCode methods.Compared with other tools in the Java library, Equalsverifier provides a simpler and more intuitive way to test the equivalent of objects.
Compared with other tools, Equalsverifier has the following advantages:
1. Simple and easy to use: only need a few lines of code using EqualSverifier.Developers only need to call the method of `Equalsverifier.ForClass (), pass in the class to be tested, and use the` .Verify () method to perform testing.This makes the Equals and HashCode methods of the test objects simple and intuitive.
2. Custom verification rules: Equalsverifier allows developers to define customized verification rules to meet more specific needs.For example, you can use the `WithRedefinEdSuperClass () method to specify the parent class of the test class, or use the method to specify the specific field value by using the method of the test class, or use the` Withprefabvalues () method.This makes Equalsverifier very flexible and suitable for different test scenarios.
Below is a simple example of Equalsverifier. It is used to test an Equals and HashCode method called a class called Student:
import nl.jqno.equalsverifier.EqualsVerifier;
public class Student {
private String name;
private int id;
// constructor and other methods
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Student student = (Student) obj;
return id == student.id && Objects.equals(name, student.name);
}
@Override
public int hashCode() {
return Objects.hash(name, id);
}
public static void main(String[] args) {
EqualsVerifier.forClass(Student.class).verify();
}
}
By calling the `Equalsverifier.ForClass (Student.class) .Verify () method, the correctness of the Equals and HashCode methods of the Student class.
All in all, Equalsverifier is an easy -to -use Java library that is used to test the Equals and HashCode methods for testing objects.Compared with other tools, it provides more intuitive and reliable methods to test the equal implementation of objects.Equalsverifier is a powerful tool for the writing of Equals and HashCode methods that follow the best practice.