Is there still no solution for ignoring setter/getter (other trivial methods) with the cobertura-maven-plugin?
Asked Answered
N

2

17

Did someone find a good solution to ignore trivial methods?
Using some automated testing like Unitils is not really an option, since the code-coverage should not go up if only getters/setters are tested!

Using cobertrua-maven-plugin version 2.5.1:
-) ignore for methods does not work <ignore>com.company.*.set*</ignore>
-) did anyone try to include a patch like http://sourceforge.net/tracker/index.php?func=detail&aid=3010530&group_id=130558&atid=720017 into the maven-plugin?
-) anyone uses a different (better?) test-plugin?

A general ignore for every get/set/is* method is also not really a good way, since these patterns can be used in other methods but simle getter/setters. Also it should be easy to guess trivial getters/setters/constructors.

I know about the question: Ignore methods in class. cobertura maven plugin but since it did not get any relevant answers, I thought I give it another shot.

Newell answered 13/2, 2012 at 13:55 Comment(0)
P
13

Since Cobertura 2.0 there is a switch to exclude trivial methods:

[Cobertura Changelog] New --ignoreTrivial switch that tells Cobertura to ignore the following in the coverage report: Getter methods that simply read a class field; Setter methods that set a class field; Constructors that only set class fields and call a super class constructor.

The cobertura-maven-plugin uses Cobertura 2.x since version 2.6 (see release notes). But i have not yet found a way to pass the switch to the maven plugin configuration.


Although there seems to be some confusion about the state of this feature (see this Jira issue), the flag does seem to work with the following configuration:

<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
  <instrumentation>
    <ignoreTrivial>true</ignoreTrivial>                 
  </instrumentation>
</configuration>
Personal answered 10/10, 2013 at 21:41 Comment(5)
brilliant, I'll test and review as soon as I got 5minsNewell
excellent, had to check the plugin code for the usage since I couldnt find it anywhere (thus, the include in the answer)Newell
@AbGator it was already included (I checked the code) and it works (its included in our cycle) ..please check before you remove already tested and working information!Newell
Sorry for the thread necro, but is there anything else I must do to make this work? I have this snippet in my <reporting><plugins><plugin> section, but the report is still complaining about simple getters and setters. Eclipse also didn't auto-complete the ignoreTrivial option. Do I need to import something else?Fast
To modify the default instrumentation behavior, you have to override the plugin configuration in the build->plugins section of your pom (see mojo.codehaus.org/cobertura-maven-plugin/usage.html section 2).Personal
H
1

The exclusion problem was fixed here:

http://jira.codehaus.org/browse/MCOBERTURA-52

and it's part of the latest release (2.5.2). It's available since 10 Sept. 2012:

http://search.maven.org/#search|gav|1|g%3A%22org.codehaus.mojo%22%20AND%20a%3A%22cobertura-maven-plugin%22
Heel answered 27/10, 2012 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.