This is a patch to the 1.9.4.1 baseline. It adds 2 new switches: --ignoreTrivial and --ignoreMethodAnnotation.
The --ignoreTrivial switch forces 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 --ignoreMethodAnnotation is used to specify an annotation that, when present on a method, will force Cobertura to ignore the method in the coverage report.
We also generate our getters and setters (as well as many constructors) using Eclipse. We don't want to spend time ensuring generated methods are covered by a JUnit test. (We trust the code generator otherwise we wouldn't use it.) On my project, we also use Eclipse to generate toString(), equals(), and hashCode() method. We put a "generated" annotation on these methods. Using these switches we are able to filter out the "noise" of generated methods in the coverage report and focus our attention on areas of the code that were written by developers. (Note: This is not a mechanism to boost coverage %, because in many cases the coverage % goes down when these methods are removed from the report.)
Thanks,
-- Tad
Diff output of patch changes
Another version of patch: zip file with entire (changed) file contents
I intend on applying all of this patch.
I have added the ignoreTrivial functionality first. It is revision 729.
I created a functional test that gives a good idea of what is considered trivial:
http://cobertura.svn.sourceforge.net/viewvc/cobertura/trunk/cobertura/test/net/sourceforge/cobertura/test/IgnoreTrivialFunctionalTest.groovy?revision=729&view=markup
This patch is an update of this patch:
https://sourceforge.net/tracker/?func=detail&aid=2035169&group_id=130558&atid=720017
It appears the ignoreTrivial functionality is Scott Frederick's from patch 1576631 (as Tad mentions in patch 2035169).
The ignoreMethodAnnotation appears to be Tad's original work although it is similar to the idea in patch 2009489 where a regex was used instead of an annotation.
Committed revision 730.
Thanks Tad and Scott!
I discovered a bug in the patch I submitted. The FirstPassMethInstrumenter.visitAnnotation() method is incorrect. Here is the corrected method:
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
// We need to convert desc so that it contains a fully-qualified classname.
// Example:
// @java.lang.Override --> passed in as this: "Ljava/lang/Override;"
String annotationDesc = desc.replace('/', '.');
// Check to see if this annotation is one of the ones that we use to
// trigger us to ignore this method
for(Iterator it = ignoreMethodAnnotations.iterator(); it.hasNext();) {
String ignoredAnnotation = (String)it.next();
if(annotationDesc.contains(ignoredAnnotation)) {
ignored = true;
break;
}
}
return super.visitAnnotation(desc, visible);
}
Corrected orginal patch! This is the new diff output of patch changes
Corrected original patch! Another version of patch: zip file with entire (changed) file contents
View and moderate all "patches Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Patches"
this arguments don't have in ant task yet.
Last edit: Anonymous 2014-04-25
This has been applied and is currently in the latest version of cobertura with an ant task.