Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude a method/branch from instrumentation cobertura

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"

like image 441
Jayan Avatar asked Jan 23 '26 13:01

Jayan


1 Answers

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!

like image 160
Klua Avatar answered Jan 26 '26 03:01

Klua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!