0

I am using Cobertura for code coverage analysis. If I run a build in Jenkins the classes in generated are contained in the coverage result but the coverage is at 0%. If I run code coverage in my workspace (Eclipse) the coverage is much higher. The coverage for the package com.my.package is ok. Have I missed some configuration?

My projects structure is as following:

- com
+- com.my
+-- com.my.package
+--- class1.java
+--- class2.java
- generated
+- classX.java
+- classY.java

My cobertura configuration in the POM-file:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <formats>
                    <format>xml</format>
                </formats>
                <check>
                    <branchRate>0</branchRate>
                    <lineRate>0</lineRate>
                    <haltOnFailure>false</haltOnFailure>
                    <totalBranchRate>0</totalBranchRate>
                    <totalLineRate>0</totalLineRate>
                    <packageLineRate>0</packageLineRate>
                    <packageBranchRate>0</packageBranchRate>
                </check>
                <instrumentation>
                    <excludes>
                        <exclude>**/*Test.class</exclude>
                    </excludes>
                </instrumentation>
            </configuration>
            <executions>
                <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>cobertura</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Kai
  • 38,985
  • 14
  • 88
  • 103
  • I had a similar problem, but wasn't satisfied with the 'don't do code coverage on generated code' answer. I managed to put together the following [solution](http://stackoverflow.com/questions/11159656/cobertura-code-coverage-for-freemarker-auto-generated-code) – amaidment Jul 03 '12 at 12:55

1 Answers1

1

Generated code should not be tested and should not be used in code coverage metrics. The reason is that you should not be testing the library that is generating the code.

I've never used Cobertura myself, but it seems that you should add something like this:

            <instrumentation>
                <excludes>
                    <exclude>**/*Test.class</exclude>
                    <exclude>generated/*.class</exclude>
                </excludes>
            </instrumentation>
Kai
  • 38,985
  • 14
  • 88
  • 103
Alan Escreet
  • 3,499
  • 2
  • 22
  • 19