When developing Java applications, I often override Object methods (usually equals and hashCode). I would like some way to systematically check that I\'m adhering to the co
[community post here, no karma involved ;) ]
Here is another code-challenge for you:
One java class, implementing a JUnit test case, with a main method able to launch JUnit on itself!
This class will also:
The test method takes a class name parameter (here: it will be itself), check if the class with that name has an equals() overridden method with "interesting values" annotations.
If it does, it will builds the appropriate instances (of itself) based on the annotations, and test equals()
This is a self-contained test class, which defines a mechanism able to be generalized to any class with an annotated overridden equals() function.
Please Use JDK6 and JUnit4.4
That class should be copied-paste in the appropriate package of an empty java project... and just run ;)
To add some more thought, in response to Nicolas (see comments):
Should annotations representing potential testing data never ever be in the class itself ?... Hey that could be a great question to ask :)