Cobertura 代码覆盖率结果不完整

发布于 2024-11-16 21:50:50 字数 1857 浏览 3 评论 0原文

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

我的项目结构如下:

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

POM 文件中的 cobertura 配置:

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黎歌 2024-11-23 21:50:50

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

我自己从未使用过 Cobertura,但似乎你应该添加这样的内容:

            <instrumentation>
                <excludes>
                    <exclude>**/*Test.class</exclude>
                    <exclude>generated/*.class</exclude>
                </excludes>
            </instrumentation>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文