如何使用 Maven (android-maven-plugin) 在 Android 中获取代码覆盖率
我有一个 Android Maven 项目(我们称之为 parent_project),其中包含各种子模块:my_library_project、app_using_my_library_project、test_project和extra_lib。
因此,结构将是这样的:
parent_project
* my_library_project (Android Library Project)
* app_using_my_library_project (Demo app that uses the Android Library Project)
* test_project (Project containing the tests instrumented against app_using_my_library_project)
* extra_lib
我想要的是使用 Maven(而不是 Ant,我已经能够使用 Ant 生成代码覆盖率报告,按照以下说明生成 Android 项目的测试覆盖率:https://wiki.jenkins-ci.org/display/JENKINS/构建+Android+应用+和+测试+项目)。
我对所使用的代码覆盖率工具没有强烈的偏好,但我更喜欢 EMMA,因为它似乎在 Android 开发世界中最常见。
我正在使用 android-maven-plugin (http://code.google.com/p/maven-android-plugin/) 的 3.0.0-alpha-12 版本,我已经尝试放入我的配置父级的 pom.xml 下一个:
<test>
<coverage>true</coverage>
<createreport>true</createreport>
</test>
但这不会产生所需的代码覆盖率报告。
那么:
- 标准Java项目和Android项目获取代码覆盖率的pom配置有什么区别吗?
- 您知道任何使用 Maven 且具有代码覆盖率的 Android 项目示例吗?
- 关于如何执行此操作有任何提示吗?
I have an Android Maven project (let's call it parent_project) that contains various submodules: my_library_project, app_using_my_library_project, test_project and extra_lib.
So, the structure would be like this:
parent_project
* my_library_project (Android Library Project)
* app_using_my_library_project (Demo app that uses the Android Library Project)
* test_project (Project containing the tests instrumented against app_using_my_library_project)
* extra_lib
What I would like is to generate test coverage for my Android project using Maven (and not Ant, I am already able to generate code coverage reports using Ant, following these instructions: https://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project).
I have no strong preference for the code coverage tool used but I would prefer EMMA, since seems the most common in the Android development world.
I am using android-maven-plugin (http://code.google.com/p/maven-android-plugin/) in its 3.0.0-alpha-12 version and I have already tried to put in the configuration of my parent's pom.xml the next:
<test>
<coverage>true</coverage>
<createreport>true</createreport>
</test>
But that does not produce the desired code coverage report.
So:
- Is there any difference between the pom configuration for getting code coverage for a standard Java project and an Android project?
- Do you know any example Android project using Maven that has code coverage?
- Any hints on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您打算坚持使用 Maven,并且想要一个 Maven 插件来完成代码覆盖工作,我认为 Cobertura 是一个更好的选择,因为 Emma 稳定的最后版本来自2005 年。
虽然在“Android 应用程序测试指南”(6 月份的最新书)今年)他们谈论了 Emma 并演示了如何使用它进行测试,我认为人们坚持使用它,因为它需要从源代码构建 Android(如果 Google 将它用于自己的操作系统开发,那么它应该是最好,对吧?)。
如果您不热衷于 Maven,我强烈建议您尝试 Robotium。
Robotium 完全支持活动、对话框、Toast、菜单和上下文菜单。
它还支持代码覆盖范围(虽然目前基于 Ant),有些人认为它是 Android 的领先测试平台之一。
编辑:
根据 Cobertura 站点,它支持 Maven 1 和 Maven 2 环境中的代码覆盖率。不过,您也可以找到 Maven 3 的示例 。
Maven 2 和 Maven 3 的 pom 配置之间存在问题。似乎要使报告正常工作,您必须基本上将旧的报告插件移动到新的 maven-site 的配置部分中插件。。 (详情请参阅文章)。
另一种选择是尝试将 Sonar 与 Maven 一起使用。 Sonar 嵌入了 cobertura(也可以选择嵌入EMMA)和一些人声明他们已经成功报告了代码覆盖率,尽管他们在使用“独立”cobertura 插件时遇到了问题。
If you're going to stick with maven, and want a plugin for maven that will do the code-coverage job, I think Cobertura is a better choice, as Emma stable last build is from 2005.
Although in "Android Application Testing Guide" (a recent book from June this year) they talk about Emma and demonstrate how to use it for testing, I think people stick to it, because it's needed to build Android from source (and if Google use it for their own OS development, it should be the best, right?).
If you're not fanatically bound to Maven, I strongly recommend to try Robotium.
Robotium has full support for Activities, Dialogs, Toasts, Menus, and Context Menus.
It also supports code coverage (Ant based though, for now) and some people recognize it as one of the leading testing platforms for Android.
Edit:
According to the Cobertura site, it supports code coverage in Maven 1 and Maven 2 environments. Although, you can find examples with Maven 3 also.
A problem exists between pom configurations of Maven 2 and Maven 3. It seems for the reporting to work you have to basically move your old reporting plugins into the configuration section of the new maven-site-plugin. (See the article for details).
Another option is to try and use Sonar with Maven. Sonar has cobertura embedded (also options to embedd EMMA) and some people state that they had successfully reported code coverage, despite they had problems using the "stand-alone" cobertura plugin.
我可以使用 emma maven 插件生成代码覆盖率报告,并在 android 应用程序项目的声纳中显示报告。只需按照 https://code.google.com/p/ 中的配置即可maven-android-plugin/wiki/EmmaMaven。
但对于图书馆项目,我的覆盖率是 0%。它不生成元数据文件。然而,当我将库项目更改为打包为 apk 时,它就像一个魅力。它在模拟器(在詹金斯中配置)中运行测试并显示覆盖率报告。
如果您专门寻找图书馆项目,这不会有帮助。如果我找到一些处理图书馆项目的解决方案,我会发布。
I could generate code coverage reported using emma maven plugin and display reports in sonar for an android application project. Just follow the configuration in https://code.google.com/p/maven-android-plugin/wiki/EmmaMaven.
But for library project I get a 0% coverage. It doesn't generate the metadata files. However as soon I change the library project to package as an apk, it works like a charm. It runs the tests in a emulator(configured in jenkins) and shows the coverage reports.
If you are looking out specifically for library project, this wont help. I will post if I find some solution which deals with library projects.