如何在 Android 中使用 Ant 过滤 EMMA 生成的测试覆盖率报告中的文件

发布于 2024-12-11 12:20:01 字数 1454 浏览 5 评论 0原文

我有一个 Android 项目,并且我正在使用 Ant 和 EMMA 正确生成测试覆盖率报告(我按照此处的说明进行操作:https://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project)

我会做什么我想知道的是如何过滤出现在 EMMA 生成的报告中的文件(例如,R 生成的类、已测试库中的文件...)。

我将 ${sdk.dir}/tools/ant/test_rules.xml 和 ${sdk.dir}/tools/ant/main_rules.xml 包含在我自己的 build.xml 文件中,并尝试更改“-emma-仪器”目标看起来像这样:

<target name="-emma-instrument" depends="compile">
    <echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
    <!-- It only instruments class files, not any external libs -->
    <emma enabled="true">
        <instr verbosity="${verbosity}"
               mode="overwrite"
               instrpath="${out.absolute.dir}/classes"
               outdir="${out.absolute.dir}/classes">

               <filter excludes="*R*" />
        </instr>
        <!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
             user defined file -->
    </emma>
</target>

我还尝试应用此处指定的 EMMA 覆盖过滤器的另一种变体 http://emma.sourceforge.net/reference_single/reference.html#instrset.filters,但这也不起作用,R 生成的文件仍然出现在覆盖率报告中。

有人知道如何解决这个问题吗?

I have an Android project and I am correctly generating test coverage reports using Ant and EMMA (I did it by following the instructions here: https://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project)

What I would like to know is how can I filter the files that appear in the report generated by EMMA (for example, the R generated classes, files in an already tested library...).

I included both ${sdk.dir}/tools/ant/test_rules.xml and ${sdk.dir}/tools/ant/main_rules.xml in my own build.xml file and there I tried to change the "-emma-instrument" target to look like that:

<target name="-emma-instrument" depends="compile">
    <echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
    <!-- It only instruments class files, not any external libs -->
    <emma enabled="true">
        <instr verbosity="${verbosity}"
               mode="overwrite"
               instrpath="${out.absolute.dir}/classes"
               outdir="${out.absolute.dir}/classes">

               <filter excludes="*R*" />
        </instr>
        <!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
             user defined file -->
    </emma>
</target>

I also tried to apply another variations of EMMA coverage filters specified here http://emma.sourceforge.net/reference_single/reference.html#instrset.filters, but that does not work either, and the R generated files still appear in the coverage report.

Anybody knows how to solve this?

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

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

发布评论

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

评论(1

韬韬不绝 2024-12-18 12:20:01

Update: Filtering is built in as of revision r18 of the android SDK, just see my answer to the linked question.

There is another question asking for this, where you've been already the half way down the road. To solve your issue just make sure, that you do not modify the test projects build file, but the one of the target project. I've got really no clue what kind of ant magic is involved in the android app build files, but of course to some extend your target projects build file must play an important role, so it's kinda logical that you've got to specify the coverage modification within the target project.

It took me the whole morning to sort this thing out, so I hope it's of some value for other developers.

As a side note, this functionality should be built-in as of revision 16 of the SDK tools.

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