Menu

#93 Ignore trivial methods & methods with "ignore" annotation

Unstable_(example)
closed-fixed
None
5
2014-08-28
2010-06-02
No

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

Discussion

  • Tad E. Smith

    Tad E. Smith - 2010-06-02

    Diff output of patch changes

     
  • Tad E. Smith

    Tad E. Smith - 2010-06-02

    Another version of patch: zip file with entire (changed) file contents

     
  • John Lewis

    John Lewis - 2010-07-08
    • assigned_to: nobody --> lewijw
    • status: open --> open-accepted
     
  • John Lewis

    John Lewis - 2010-07-08

    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!

     
  • Tad E. Smith

    Tad E. Smith - 2010-07-17

    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);
    }

     
  • Tad E. Smith

    Tad E. Smith - 2010-07-17

    Corrected orginal patch! This is the new diff output of patch changes

     
  • Tad E. Smith

    Tad E. Smith - 2010-07-17

    Corrected original patch! Another version of patch: zip file with entire (changed) file contents

     
  • Anonymous

    Anonymous - 2013-02-06

    this arguments don't have in ant task yet.

     

    Last edit: Anonymous 2014-04-25
  • Steven Christou

    Steven Christou - 2013-08-18
    • status: open-accepted --> closed-fixed
    • Group: --> Unstable_(example)
     
  • Steven Christou

    Steven Christou - 2013-08-18

    This has been applied and is currently in the latest version of cobertura with an ant task.