3

I need to skip certain methods or code segments from instrumentation and code coverage. That lead me to Exclude methods from code coverage with Cobertura.

Then the cobertura ant page http://cobertura.sourceforge.net/anttaskreference.html said ... You can tell Cobertura to ignore certain classes by passing in "ignore" regular expressions. The ignore pattern can be any valid perl 5 regular expression. This will ignore any calls to any method that matches the ignore regular expression. It will NOT skip over these classes during instrumention. To exclude classes from being instrumented, either exclude them from your fileset or use the alternative method below and specify an excludeClasses pattern. ....

From the source code of net.sourceforge.cobertura.ant.InstrumentTask.java

        for (int i = 0; i < ignoreBranchesRegexs.size(); i++) {
            IgnoreBranches ignoreBranchesRegex = (IgnoreBranches)ignoreBranchesRegexs.get(i);
            builder.addArg("--ignoreBranches", ignoreBranchesRegex.getRegex());
        }

What does the "--ignoreBranches" do? What is the pattern expected? I am going to try it. If you have used above option, please share your "command line"

Community
  • 1
  • 1
Jayan
  • 18,003
  • 15
  • 89
  • 143

2 Answers2

1

Please see this link. http://svnsearch.org/svnsearch/repos/COBERTURA/search?start-index=60& Apparently, there is an @Ignore method annotation that was added for this purpose. As for code blocks, I would try the same thing. Let me know if this works!

Klua
  • 11
  • 3
0

This isn't a direct answer to the question, but my take on it would be: "Cover it." Don't exclude things from coverage reports. Fix the coverage.

Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
  • What about the branch coverage? do you imply that you write test cases for every if statement for an auto generated equals method? – add9 Dec 03 '12 at 17:28
  • @imellan: Resurrecting an old question, but still relevant. If it's code, cover it, regardless of who wrote it. A better alternative to dumb, generated code might be an equals helper like Guava [Objects.equal()](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Objects.html#equal(java.lang.Object, java.lang.Object)) or commons-lang [EqualsBuilder](http://commons.apache.org/lang/api-2.3/org/apache/commons/lang/builder/EqualsBuilder.html). The bottom line is: if you intend for code to do something, there better be tests expressing your intent. – Ryan Stewart Dec 15 '12 at 21:46