Java Code Coverage Ideas?

Jack Dreep :

I am working on a Java project where I have an ant build, which runs JUnit tests, which are monitored by Cobertura. That works great and we have kept our coverage very high. For some classes, like Hibernate entities, we have minimal code in them, but have equals and hashCode methods. Testing those is a huge pain, and drags down the coverage percentages. We've tried using EqualsVerifier two classes have references to each other, which occurs often in Hibernate entities.

We've considered using Commons EqualsBuilder, but then we lose the ability to have IDE's autogenerate the equals/hashCode methods. I know EqualsBuilder also can be done through reflection, but we don't want to lose runtime performance just for build-time unit test coverage.

An ideal situation would be if we could tell Cobertura to just ignore equals and hashCode methods, but the patches out there require us to annotate our classes, which seems a bit awkward.

So, I'm hoping for ideas from others as to what works well in such instances. Does anyone have any ideas for how to get this done?

Thanks!

Nathan Feger :

It seems to me like you need to make a decision: Either equals and hashCode are not important, and in that event you should just ignore the < 100% code coverage metric (or figure out how to ignore a method). Or they are important, and you should write the unit tests to exercise them. It may not be fun, but it sounds like you care if these methods work properly. In which case, you probably need to test them.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related