我可以合并来自单元和集成测试目标的 Emma 覆盖率数据吗?

发布于 2024-08-15 13:43:50 字数 259 浏览 6 评论 0原文

我们使用构建链设置 TeamCity 构建,以便我们的单元测试和集成测试可以在由提交触发时并行运行:

  • 构建链 - 依赖于:
    • 单元测试
    • 集成测试

我正在寻找一种方法,我们可以组合/合并构建链中单元和集成测试生成的覆​​盖率数据,以便我们可以更好地了解实际情况 代码被两者结合起来覆盖。

然后,计划是能够监视已提交代码的覆盖范围的变化,如果百分比下降,则可能会导致构建失败!

We have our TeamCity builds set up using a build chain, so that our unit tests and and integration tests can run in parallel when triggered by a commit:

  • Build Chain - dependant on:
    • Unit tests
    • Integration tests

I am looking for a way that we can combine/merge the coverage data generated by the unit and integration tests in the build chain, so that we can get a better picture of how much actual code is covered by the two combined.

The plan then is to be able to monitor changes in coverage of committed code, and perhaps failing builds if percentages fall!

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

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

发布评论

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

评论(3

静水深流 2024-08-22 13:43:50

我已经设置了“构建链”目标,以便单元和集成目标中的覆盖文件(*.em、*.ec)可供使用。

我专门为构建链目标创建了一个 ant 构建文件(在 emma doco 的帮助下!):

<project name="coverage-merge" basedir="." default="all">
    <!-- directory that contains emma.jar and emma_ant.jar: -->
    <property name="emma.dir" value="${basedir}/lib"/>
    <property name="coverage.dir" location="${basedir}/coverage"/>

    <path id="emma.lib">
        <pathelement location="${emma.dir}/emma-teamcity-3.1.1.jar"/>
        <pathelement location="${emma.dir}/emma_ant-2.0.5312.jar"/>
    </path>

    <taskdef resource="emma_ant.properties" classpathref="emma.lib"/>

    <target name="all" depends="-report"/>

    <target name="-report">
        <emma>
            <report sourcepath="${src.dir}" sort="+block,+name,+method,+class" 
                    metrics="method:70,block:80,line:80,class:100">
                <infileset dir="${coverage.dir}" includes="**/*.em, **/*.ec"/>

                <!-- for every type of report desired, configure a nested
                     element; various report parameters
                     can be inherited from the parent <report>
                     and individually overridden for each report type:
                -->
                <txt outfile="${coverage.dir}/coverage.txt" depth="package" 
                        columns="class,method,block,line,name"/>
                <xml outfile="${coverage.dir}/coverage.xml" depth="package"/>
                <html outfile="${coverage.dir}/coverage.html" depth="method" 
                        columns="name,class,method,block,line"/>
            </report>
        </emma>
    </target>
</project>

...它将所有覆盖率文件合并到一个报告中!

reportmetrics 参数设置 html 报告的突出显示阈值,以便低于阈值的包和文件的百分比以红色突出显示。

修改 xml 输出将允许我使用类似 andariel 的东西对结果运行 xpath,然后强制如果未达到阈值,构建就会失败!

I have set up the 'build chain' target so that the coverage files (*.em, *.ec) from the unit and integration targets are available to it.

I created an ant build file specifically for the build chain target (with help from the emma doco!):

<project name="coverage-merge" basedir="." default="all">
    <!-- directory that contains emma.jar and emma_ant.jar: -->
    <property name="emma.dir" value="${basedir}/lib"/>
    <property name="coverage.dir" location="${basedir}/coverage"/>

    <path id="emma.lib">
        <pathelement location="${emma.dir}/emma-teamcity-3.1.1.jar"/>
        <pathelement location="${emma.dir}/emma_ant-2.0.5312.jar"/>
    </path>

    <taskdef resource="emma_ant.properties" classpathref="emma.lib"/>

    <target name="all" depends="-report"/>

    <target name="-report">
        <emma>
            <report sourcepath="${src.dir}" sort="+block,+name,+method,+class" 
                    metrics="method:70,block:80,line:80,class:100">
                <infileset dir="${coverage.dir}" includes="**/*.em, **/*.ec"/>

                <!-- for every type of report desired, configure a nested
                     element; various report parameters
                     can be inherited from the parent <report>
                     and individually overridden for each report type:
                -->
                <txt outfile="${coverage.dir}/coverage.txt" depth="package" 
                        columns="class,method,block,line,name"/>
                <xml outfile="${coverage.dir}/coverage.xml" depth="package"/>
                <html outfile="${coverage.dir}/coverage.html" depth="method" 
                        columns="name,class,method,block,line"/>
            </report>
        </emma>
    </target>
</project>

...which merges all the coverage files into a single report!

The metrics parameter of report sets the highlight threshold for the html report, so that the percentages against packages and files that are lower than the threshold are highlighted in red.

Modifying the xml output will allow me to use something like andariel to run an xpath over the results, and then force the build to fail if thresholds are not met!

离鸿 2024-08-22 13:43:50

根据 TC 的 Emma 文档

所有的coverage.* 文件都会在构建开始时被删除,因此您必须确保在构建中执行源的完全重新编译以获得实际的coverage.em 文件。

我为解决此问题所做的工作如下:

  • 在 teamcity 构建步骤配置中使用 -out emma.em ,并确保 merge 选项设置为 true > 保存检测数据。
  • 最后一步生成覆盖率报告时,使用ant的move任务
    以重命名为默认名称。
  • emma报告将采用默认的em文件来生成报告。

希望这可以帮助任何人获得一份累积的艾玛报道报告。

Per TC's Emma doc

All coverage.* files are removed in the beginning of the build, so you have to ensure that full recompilation of sources is performed in the build to have the actual coverage.em file.

What I did to workaround this is below:

  • Use -out emma.em in teamcity build steps config, and make sure merge option is set to true to preserve the instrumented data.
  • In the last step when coverage report is generated, use ant's move task
    <move file="$YOUR_PATH/emma.em" tofile="$YOUR_PATH/coverage.em"/> to rename to the default one.
  • The emma report will pick up the default em file to generate report.

Hope this helps whoever whats to have an accumulated emma coverage report.

水染的天色ゝ 2024-08-22 13:43:50

我遇到的大多数代码覆盖工具似乎都没有办法组合来自不同或重叠子系统的测试结果。正如您所指出的,这是一项非常有用的能力。

我们的SD 测试覆盖率工具确实具有此功能,并且可用于Java、C、C++、C#、PHP 和 COBOL。事实上,SD 测试覆盖率工具可以将多种语言的测试覆盖率数据组合成单个整体结果,以便您可以获得多语言应用程序的测试覆盖率概述。它能够显示所有涉及的源语言的覆盖范围,并提供摘要报告。

Most of the code coverage tools I've encountered do not seem to have a way to combine test results from different or overlapping subsystems. As you have pointed out, this is a very useful ability.

Our SD Test Coverage tools do have this ability and are available for Java, C, C++, C#, PHP and COBOL. In fact, the SD test coverage tools can combine test coverage data from multiple languages into a single monolithic result, so that you can get an overview of test coverage for your multi-lingual applications. It is able to show the coverage on all the source langauges involved, as well as provide summary reports.

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