I just want to know if there is a best practice or a common way of testing equal to the implementation in objects. I am referring to a validation method that has been overridden.
public boolean equals(Object o)
I used that kind of logic. (Assume the number and name must be equal in order to get the truth)
Dog d1 = new Dog(1,"Alvin"); Dog d2 = new Dog(2,"Alvin"); Assert.assertFalse(d1.equals(null)); Assert.assertFalse(d1.equals(d2)); d2.setId(1); d2.setName("Kelvin"); Assert.assertFalse(d1.equals(d2)); d2.setName("Alvin"); Assert.assertTrue(d1.equals(d2)); Assert.assertTrue(d1.equals(d1));
But when there are many fields, this task is very large and boring, so my question is whether there is any framework, tool, option, everything that makes this easier, and can prove that the method has been overridden correctly. thanks.
I know that overriding a method is equal to depending on the required logic, but also creating a test case, so you are looking for a standard way to test a method that avoids large codes in test cases if there is an explicit or some kind of sentence you may have.
java equality equals junit testing
Koitoer
source share