Cobertura代码覆盖率结果不完整 [英] Cobertura code coverage results not complete

查看:204
本文介绍了Cobertura代码覆盖率结果不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cobertura进行代码覆盖率分析.如果我在Jenkins中运行构建,则覆盖范围结果中将包含generated中的类,但覆盖范围为 0%.如果我在工作区(Eclipse)中运行代码覆盖率,则覆盖率会更高.包com.my.package的覆盖范围还可以.我错过了一些配置吗?

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?

我的项目结构如下:


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

我在pom文件中的cobertura配置:

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>

推荐答案

不应测试生成的代码,也不应该在代码覆盖率指标中使用生成的代码.原因是您不应该测试正在生成代码的库.

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.

我本人从未使用过Cobertura,但似乎您应该添加以下内容:

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>

这篇关于Cobertura代码覆盖率结果不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆