When writing Java classes, it's not uncommon to generate methods using your IDE such as
But once you've generated them using the IDE, they become part of your codebase (in SCM) and therefore all quality measuring means apply.
Especially the equals and hashcode methods contain lots of conditions. If I don't write unit tests, the score on code coverage (line-, condition-, mutation-) is pretty low, especially if the class under test is not that large.
Some coverage tools support filtering (i.e. cobertura), others (i.e. jacoco) don't. But the coverage tools reveal just a symptom – untested code – and therefore I'm not asking, whether to suppress/ignore the symptom, but how to deal with the root cause.
Question is: should I write unit tests for these methods?
- If yes, what are good reasons to do so? And what is a sensible approach?
- If no, why not?
I'm not asking for generated classes in general, like JAXB pojos, WS-Clients etc, which can be easily generated automatically and excluded from coverage analysis.