I would like to exclude hashCode
and equals
from clover report.
Some configuration example would be nice.

- 18,436
- 13
- 66
- 75

- 3,305
- 4
- 27
- 52
-
3Why wouldn't you want to test those methods? I think it's a mistake. – duffymo Jan 03 '12 at 10:53
-
did you figured out any solutions for this? would be really nice if you could share – add9 Dec 04 '12 at 09:01
-
no.... still no solution, actually I've ignored this problem for now.... – Maciej Miklas Dec 06 '12 at 09:39
2 Answers
I would like to exclude hashCode and equals from clover report.
I would respectfully suggest that you actually test these methods instead of avoiding them. Serious bugs can occur if they are not consistent with specifications. I've encountered NPEs and other problems in poorly written hashCode
and equals
methods as well. Here's a great link with a number of ways that you can test your methods:
We use the following LocalEqualsHashCodeTest
which can be extended by a unit test:
You then define a createInstance()
method which returns an instance of your class and a createNotEqualInstance()
method which returns another instance that is not equal to the first one.
-
3I did not ask whenever it makes sense to test equals/hashcode, or how to do it, but how to exclude them from clover – Maciej Miklas Dec 06 '12 at 09:37
-
4That's fine @MaciejMiklas. I just wanted to give you a different way of looking at things. Tons of answers on SO don't address the specific question but encourage the poster to look it differently. The fact is that I don't know but I consider it a bad practice to not test them. – Gray Dec 06 '12 at 13:10
-
3Funny, I came here looking for a way to exclude from my cobertura site report hashcode and equals, but actually your way (testing them with that utility class) seems much more better. So thanks! (btw, i dont understand why OP was so harsh about your answer...) – juancancela May 12 '14 at 02:04
You have to do two steps:
1) Define method contexts in the <clover-setup> task containing regular expressions for methods you want to match, for example:
<clover-setup ...>
<methodContext name="equals" regexp="public boolean equals\(.*\)"/>
<methodContext name="hashCode" regexp="public int hashCode\(\)"/>
</clover-setup>
2) Define which method contexts shall be excluded from the report in the <clover-report> task
<clover-report>
<current outfile="clover_html" title="My Coverage">
<format type="html" filter="equals,hashCode"/>
</current>
More information:

- 748
- 6
- 13