Ignoring report generation for specific classes in cobertura maven plugin

混江龙づ霸主 提交于 2019-12-04 02:25:25

Cobertura maven plugin does not respect exclusion and ignoring for report generation.It does so for instrumentation though.

Known bug reported at : http://jira.codehaus.org/browse/MCOBERTURA-52

You can exclude classes from your cobertura report by moving the <plugin> block from the <reporting> block to your <build> block in your pom.xml.

I had a similar problem and found a very helpful tutorial: http://www.java-tutorial.ch/software-testing/maven-cobertura

The solution is quite close to the answer that rdvdijk posted. The plugin information should be in the build section as well as in the reporting section. But the exclude information should be placed in the build section of the pom.

Use excludes i.o. ignores.
This is how I exclude specific classes from cobertura:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
    <instrumentation>
        <excludes>
            <exclude>com/bnpp/ecom/**/*Test.class</exclude>
            <exclude>com/lrc/web/WicketApplication.class</exclude>
            <exclude>com/lrc/service/HeartBeatWebServiceMock.class</exclude>
        </excludes>
    </instrumentation>
</configuration>

greetz,
Stijn

I could successfully generate a cobertura coverage report by ignoring the *Test files from the project after changing the cobertura-maven-plugin version from 2.6 to 2.4 (as mentioned by Stjin geukens in the above comments).

Please find the complete maven plugin details below:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>com/services/impl/*Test.class</exclude>
                            <exclude>com/exceptions/*Test.class</exclude>
                            <exclude>com/services/*Test.class</exclude>
                            <exclude>com/utils/*Test.class</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

P.S: I am not sure what is the issue with 2.6 version of the plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!