eclipse Android 代码覆盖率

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6254771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:24:20  来源:igfitidea点击:

Code coverage for Android

androideclipseemma

提问by Gheghen

Possible Duplicate:
Android test code coverage, Eclipse

可能的重复:
Android 测试代码覆盖率,Eclipse

Its really frustrating to see there is no documentation for how to use EMMA for Android apps in Eclipse. Has anyone managed to work with EMMA in eclipse for Android apps? Without checking out the whole android source and do all the hackery?

看到没有关于如何在 Eclipse 中为 Android 应用程序使用 EMMA 的文档,真的很令人沮丧。有没有人设法在 Eclipse 中为 Android 应用程序使用 EMMA?不检查整个 android 源代码并做所有的hackery?

采纳答案by bancer

If you have <path to test project>/build.xmlfile rename it.

如果你有<path to test project>/build.xml文件重命名它。

I was able to generate test coverage report by executing following from the console:

我能够通过从控制台执行以下操作来生成测试覆盖率报告:

<path to android tools>android update test-project -m <path to app project> -p <path to test project>+ Enter,

<path to android tools>android update test-project -m <path to app project> -p <path to test project>+ Enter,

cd <path to test project>+ Enter,

cd <path to test project>+ Enter,

ant emma debug install test+ Enter,

ant emma debug install test+ Enter,

where <path to android tools>is /opt/android-sdk-linux/tools/on my machine - the folder where android SDK is installed.

这里<path to android tools>/opt/android-sdk-linux/tools/我的机器上-安装Android SDK中的文件夹。

This generated <path to test project>/bin/coverage.htmlfile.

这个生成的<path to test project>/bin/coverage.html文件。

If you get "wrong JAVA_HOME" error execute gksu gedit /etc/environment+ Enter, correct JAVA_HOME, save the file, log out or reboot and try again.

如果您收到“错误的 JAVA_HOME”错误,请执行gksu gedit /etc/environment+ Enter、更正JAVA_HOME、保存文件、注销或重新启动并重试。

Source: http://blog.rabidgremlin.com/2010/11/19/android-tips-generating-a-coverage-report-for-your-unit-tests/

资料来源:http: //blog.rabidgremlin.com/2010/11/19/android-tips-generating-a-coverage-report-for-your-unit-tests/

回答by dongshengcn

This does not answer your question directly, but I would suggest you to take a look at writing test with Robolectric: http://pivotal.github.com/robolectric/

这不能直接回答您的问题,但我建议您看一下使用 Robolectric 编写测试:http://pivotal.github.com/robolectric/

With Robolectric, you can write your testing running inside JVM instead of Delvik VM. That means you can use almost any code coverage tool for JAVA. You might have to change your code a bit so you can write your Robolectric, and also you have not start hacking Robolectric too. To me, it is just a better way to write test.

使用 Robolectric,您可以编写在 JVM 而不是 Delvik VM 中运行的测试。这意味着您几乎可以使用任何 JAVA 代码覆盖工具。您可能需要稍微更改您的代码,以便您可以编写您的 Robolectric,而且您还没有开始对 Robolectric 进行黑客攻击。对我来说,这只是编写测试的更好方法。

回答by Android

i found few links it may be helpful http://blog.pboos.ch/2011/06/coverage-fo-android-tests/you can also check How to use EMMA code coverage in androidhope it works for you

我发现很少有链接可能会有所帮助http://blog.pboos.ch/2011/06/coverage-fo-android-tests/您还可以查看如何在 android 中使用 EMMA 代码覆盖率希望它对您 有用

回答by gav

Unfortunately I believe EMMA is not applicable to Apps developed via the SDK. That is unless things have changed since I last read up on the topic. The tools are designed for use with the OS itself and as such there's no way of using it with your APK that I know of.

不幸的是,我认为 EMMA 不适用于通过 SDK 开发的应用程序。除非自从我上次阅读该主题以来情况发生了变化。这些工具专为与操作系统本身一起使用而设计,因此我知道无法将它与您的 APK 一起使用。

You may find the following related post useful - EMMA Code Coverage in Android.

您可能会发现以下相关帖子很有用 - Android 中的 EMMA 代码覆盖率