艾玛不生成coverage.ec [英] Emma does not generate coverage.ec

查看:46
本文介绍了艾玛不生成coverage.ec的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了 Emma,它曾经对我有用.然后我们更改了源代码,现在它根本不生成 coverage.ec.它确实生成 coverage.em.接近测试结束时,它有错误消息:

I setup Emma and it used to work for me. Then we had source code changes and now it doesn't generate coverage.ec at all. It does generate coverage.em. Near the end of testing, it has error messages:

[exec] INSTRUMENTATION_CODE: 0
[echo] Downloading coverage file into project directory...
[exec] remote object '/sdcard/coverage.ec' does not exist

BUILD FAILED
/var/lib/jenkins/android-sdk-linux_x86/tools/ant/build.xml:1056: exec returned: 1.

build.xml 的第 1056 行是

Line 1056 of build.xml is

"{adb}" failonerror="true".

我看到我的桌面上确实有 coverage.em,这意味着我的代码已经过检测.

I see that I do have coverage.em on the desktop, which means my code are instrumented.

我在 \test 下使用的命令是

the command I use under the \test is

ant emma debug install test

这以前对我有用.运行代码覆盖率对我来说总是崩溃,通常是在单元测试结束时,但它总是能让我得到一些覆盖率.现在它崩溃了并且不会产生 coverage.em.

This worked for me before. Running code coverage always crashes for me, usually near the end of the unit test, but it'd always get me some coverage. Now it crashes out and doesn't produce coverage.em.

我也尝试访问 /sdcard/,它完全可以访问和写入.

I also tried to access /sdcard/ and it's perfectly accessible and writable.

这已经阻止了我好几天,任何输入都将不胜感激.我也是 Android、Ant 和 Emma 的新手,谢谢!!

This has blocked me for days, any input would be much appreciated. I am also new to all this Android, Ant and Emma, so thanks!!

更新:我刚刚清理了环境并再次运行命令.现在也不再生成coverage.em.这告诉我源代码没有被检测.但是我上面使用的命令应该检测项目,它的测试项目,安装并开始测试.除了将coverage.ec 位置更改为/sdcard/coverage.ec 之外,我没有更改build.xml 中的emma def.这是因为默认情况下它会转到/data/data,而我无权访问此手机上的数据/数据

Update: I just cleaned up the environment and ran the command again.Now coverage.em is no longer generated either. Which tells me the source code are not instrumented. But the command I used above should instrument project, its test project, install and start test. I didn't change emma def in build.xml except to change the coverage.ec location to /sdcard/coverage.ec. This is because by default it goes to /data/data, and I don't have permission to access data/data on this phone

我使用的是 Android SDK 的 r15,以及默认的 build.xml.我只将coverage.ec 的路径更改为/sdcard/coverage.ec.运行检测

I am using r15 of Android SDK, and the default build.xml. I only changed the path to coverage.ec to /sdcard/coverage.ec. To run instrumentation

 Go to main_project
 $andriod update project -p .
 Go to main_prject\test
 $android update project -m ../ -p .
 To start code code
 $ant emma debug install test

它生成了 main_project-instrumented.apk 和 test_project-debug.apk.两者都已安装,我可以看到它在执行测试.

It generated main_project-instrumented.apk and test_project-debug.apk. Both are installed and I can see it executes testing.

推荐答案

您必须先使用 android 命令行工具制作一个测试项目.

You have to make a test project with the android command line tools first.

假设您的项目存储在 D:\AndroidProject 并且您针对 android API 级别 8 进行编程.首先您使用此命令创建项目:

Assuming your project is stored in D:\AndroidProject and your programming against android API level 8. First you use this command to create the project:

android update project --path ./ --name blabla~ --target android-8 --subprojects 

然后为测试项目创建一个文件夹并导航到该文件夹​​:

Then create an folder for the test project and navigate into that folder:

mkdir Android_test
cd Android_test

然后使用以下命令创建android测试项目

Then create the android test project with the below command

 android create test-project --main ../AndroidProject --path ./

带有 emma 覆盖率报告的 Ant 构建(带 root)

执行此命令(来自 jenkins 选择和构建步骤)以使用 emma 报告完成构建:

Ant building with emma coverage report (with root)

Execute this command (from jenkins select and build step) to get a build done with emma reporting:

ant emma debug install test

注意 : 为此,您必须连接有 root 权限的设备或模拟器,然后执行 ant 命令!

Caution : For this to work you have to connect rooted device or emulator, then execute ant command!

如果您不想 root 设备,另一种解决方案是更改这些覆盖率报告的位置.为此,您应该修改 build.xml 文件.

If you don't want to root your device an alternative solution is to alter the location of these coverage reports. For this you should modify the build.xml file.

(你应该在谷歌上搜索更多信息,这里简要解释)

打开 build.xml ->找到存储 coverage.ec 文件的位置.在大多数情况下,这将存储在 /data/data/com.example.Android/coverage.ec

Open the build.xml -> find the location where the coverage.ec file is stored. In most cases this will be stored in /data/data/com.example.Android/coverage.ec

这里的问题是 /data/data/~~~ 路径受到保护(因此需要根).

The problem here is that the /data/data/~~~ path is protected (hence the required root).

无论如何~你可以在你的测试项目文件夹/bin中得到一个coverage.html文件.接下来的步骤解释了如何更改它以将此文件保存在 /sdcard 上!

anyway~ you can get a coverage.html file in your test project folder/bin. The next steps explain how to change this to save this file on the /sdcardinstead!

你可以打开你的 build.xml 文件,在最后一行~你可以找到命令 import ~~~ build.xml 这意味着你的 build.xml文件将导入另一个 build.xml 文件.

You can open your build.xml file and at the last line ~ you can find the command import ~~~ build.xml which means that your build.xml file will import anoother build.xml file.

另一个 build.xml 文件是 android SDK 的一部分,位于 ${Android-sdk}/tools/ant/build.xml.

The other build.xml file is part of the android SDK and is located at ${Android-sdk}/tools/ant/build.xml.

我们无法更改此文件(不会遇到麻烦),因此请将完整文件复制到其他位置或直接复制到您的项目 build.xml 文件中.

We can't change this file (without getting into trouble) so instead copy the complete file to an alternative location or directly into your projects build.xml file.

无论您选择做什么,都不要忘记调整或更改 build.xml 文件中的导入语句.

这是您需要在新的 build.xml 文件中更改的内容:

This is what you need to change in that new build.xml file:

  • 擦除import=~~build.xml
  • 擦除第一行 xml=ejkwjkw?e jw ""project = "android_rule" ~~ ~blabla)
  • 和最后一行 /project
  • 更新地址为/sdcard/coverage.ec
  • Erase the import= ~~build.xml
  • Erase the first line which is xml=ejkwjkw?e jw ""project = "android_rule" ~~ ~blabla)
  • and last line /project
  • update address to /sdcard/coverage.ec

然后就可以得到coverage.ec文件了~

Then, you can get coverage.ec file~

这篇关于艾玛不生成coverage.ec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆