如何在 Android 中使用 Ant 过滤 EMMA 生成的测试覆盖率报告中的文件
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:从 android SDK 的 r18 修订版开始,过滤功能已内置,请参阅我对链接问题的回答。
还有另一个问题 要求这个,你已经走了一半了。要解决您的问题,只需确保您不修改测试项目构建文件,而是修改目标项目构建文件。我真的不知道 Android 应用程序构建文件中涉及什么样的蚂蚁魔法,但当然,在某种程度上,你的目标项目构建文件必须发挥重要作用,所以你必须指定目标项目内的覆盖范围修改。
我花了一上午的时间来解决这个问题,所以我希望它对其他开发人员有一些价值。
附带说明一下,此功能应该自修订版 16 起内置 SDK 工具。
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.