jeudi 26 mai 2016

Unit testing Equals, hashcode and comparator - asserting contracts

After reading Joshua Blosh's Effective Java 2nd edition, I decided to implement equals, hashcode and comparable(where applicable) to every class I have been implementing.

I have written a generic unit test class for equals, hashcode and comparable that will test every contract of each function.

I've attached the generic tester class for anyone who would be interested in seeing them.

My question is, am I overkilling the testing? Have I missed any clause in the equals, hashcode and compareTo contract? These is a tester class I've written once, and used numerous times. However, working on my own, I have not had the chance to get a second opinion with fellow developers.

EqualsContractTester.java

HashcodeContractTester.java

ComparableTester.java

Thanks in advance,

Lucas

Aucun commentaire:

Enregistrer un commentaire