Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude specific methods from code coverage from cobertura?

I was trying to ignore all the toString() methods from instrumentation using following configuration. This wasn't really working? This is using cobertura as maven plugin. This was based on a previous answer Exclude methods from code coverage with Cobertura.

<instrumentation>
    <ignores>
        <ignore>toString</ignore>
    </ignores>
</instrumentation>

What do you think I'm doing wrong. I wasn't able to find an example for this on the cobertura documentation.

like image 977
chinto Avatar asked Aug 23 '10 05:08

chinto


People also ask

How do you exclude code coverage methods?

The easiest way to exclude code from code coverage analysis is to use ExcludeFromCodeCoverage attribute. This attribute tells tooling that class or some of its members are not planned to be covered with tests. EditFormModel class shown above can be left out from code coverage by simply adding the attribute.

How do you exclude methods in JaCoCo code coverage?

You can set lombok. addLombokGeneratedAnnotation = true into lombok. config in the root of project. After that, all Lombok-generated code will be ignored by Jacoco.

How does cobertura check code coverage?

Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.

Which classes are excluded from code coverage calculation?

Test classes (classes that are annotated with @isTest ) are excluded from the code coverage calculation. This exclusion applies to all test classes regardless of what they contain—test methods or utility methods used for testing.


1 Answers

cobertura-ant reference

"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."

<cobertura-instrument todir="${instrumented.dir}">
    <ignore regex="org.apache.log4j.*" />
    ...
</cobertura-instrument>

I believe you have to change "ignores" to "ignore" and use a regular expression to define the whole class name before the method (or just an * in you case to exclude toString from any class).

like image 176
Marco Avatar answered Oct 14 '22 17:10

Marco