Cobertura exclude vs ignore
Asked Answered
A

3

13

I see that in the cobertura-maven-plugin, I can configure my instrumentation with both excludes and ignores. What is the difference between these two?

Alarise answered 17/9, 2014 at 21:52 Comment(1)
Possibly related: #15235414Furtive
T
2

The maven plugin does not contain any documentation for this configuration options (but they are included in the docs). The ant cobertura doc contains the following documentation:

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.

See also: https://github.com/cobertura/cobertura/wiki/Ant-Task-Reference#cobertura-instrument-task

Tafoya answered 2/1, 2015 at 12:0 Comment(1)
regular expression or globbing expression?Gandzha
G
15

Really sorry, but parroting the horrible documentation is not helpful. You quoted:

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.

This inconsistent paragraph starts by stating "...to ignore certain classes by passing in 'ignore' regular expressions.", then a second sentence later, "This will ignore any calls to any method that matches the ignore regular expression."

Well, so which is it? Does "ignore" ignore classes or methods? The command-line reference seems to imply ignore is ignoring a line of code based on RegEx matching (I wish that was true):

None of these interpretations works for <ignore> in the maven plugin.

Experimentally I have found that <exclude> is the way to exclude at the class-level. I have not found a way to exclude at a granularity less then class. However, what they also don't tell you is that <exclude> expects a relative filesystem path, not a Java package.class expression, which means <exclude> expects e.g. one/two/three/Myclass.class, rather then "one.two.three.Myclass".

Gem answered 2/4, 2015 at 1:29 Comment(0)
L
11

Ignore and exclude really function nothing alike. Exclude will remove a file from Cobertura's scan. Ignore will remove all usages of a class from contributing to line coverage.

Consider the following code snippet:

public class Foo {
     public void someMethod() {
         Bar bar = new Bar();
     }
}

If you configure <exclude>Foo.class</exclude>, then the entirety of the Foo class will not show up on your reporting.

Semi-confusingly, if you configure <ignore>Foo.class</ignore>, then Foo will still show up on your reporting, but uses of Foo in other classes will be ignored.

If you configure <ignore>Bar.class</ignore>, then the scan of Foo will ignore the line in which Bar is initialized.

To really make that stick, let's talk about why you would use ignore. Let's say that there is an object (such as a Logger) that you do not want to show up in the code coverage scan of any classes. Ignore allows you to do this.

Leninism answered 12/4, 2016 at 22:16 Comment(0)
T
2

The maven plugin does not contain any documentation for this configuration options (but they are included in the docs). The ant cobertura doc contains the following documentation:

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.

See also: https://github.com/cobertura/cobertura/wiki/Ant-Task-Reference#cobertura-instrument-task

Tafoya answered 2/1, 2015 at 12:0 Comment(1)
regular expression or globbing expression?Gandzha

© 2022 - 2024 — McMap. All rights reserved.