Maciej Miklas
Maciej Miklas

Reputation: 3330

How can I exclude a methods (hashcode and equals) from the clover coverage report?

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

Upvotes: 6

Views: 4322

Answers (2)

Gray
Gray

Reputation: 116878

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:

How should one unit test the hashCode-equals contract?

We use the following LocalEqualsHashCodeTest which can be extended by a unit test:

http://pastebin.com/L03fHAjv

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.

Upvotes: 3

Marek
Marek

Reputation: 748

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:

Upvotes: 1

Related Questions