Emma 不生成coverage.ec

发布于 2024-12-22 21:40:39 字数 1406 浏览 5 评论 0原文

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

[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 行是

"{adb}" failonerror="true".

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

我在 \test 下使用的命令是

ant emma debug install test

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

我还尝试访问 /sdcard/ 并且它完全可以访问和写入。

这已经阻止了我好几天,任何意见将不胜感激。我对 Android、Ant 和 Emma 都是新手,所以谢谢!!

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

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

 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。两者都已安装,我可以看到它正在执行测试。

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.

Line 1056 of build.xml is

"{adb}" failonerror="true".

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

the command I use under the \test is

ant emma debug install test

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.

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

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!!

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

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

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

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

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

发布评论

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

评论(2

淡笑忘祈一世凡恋 2024-12-29 21:40:39

您必须首先使用 android 命令行工具创建一个测试项目。

创建项目&测试项目

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

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

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

mkdir Android_test
cd Android_test

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

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

使用 emma 覆盖率报告进行 Ant 构建(使用 root)

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

ant emma debug install test

注意 : 为了这个对你有用必须连接root设备或模拟器,然后执行ant命令!

更改构建 xml 文件(因此不需要 root)

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

(您应该通过谷歌搜索以获取更多信息,此处简要说明)

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

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

无论如何~您可以在测试项目文件夹/bin 中获取一个 coverage.html 文件。接下来的步骤将解释如何更改此设置以将此文件保存在 /sdcard 上!

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

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

build.xml 文件所需的更改

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

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

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

  • 擦除 import= ~~build.xml
  • 删除第一行 xml=ejkwjkw?e jw ""project = "android_rule" ~~ ~blabla)
  • 和最后一行 /project
  • 将地址更新为/sdcard/coverage.ec

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

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

Create Project & Test Project

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

Then create the android test project with the below command

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

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

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

Change Build xml file (so no root is required)

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.

(you should googling about that for more information, briefly explained here)

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

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

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!

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.

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

Required changes for build.xml file

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.

Don't forget to adapt or change the import statement in your build.xml file whatever you choose to do.

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

  • 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

Then, you can get coverage.ec file~

七月上 2024-12-29 21:40:39

将 SDK 更新到 r16 后,我遇到了此问题:Emma 代码覆盖率不起作用在工具的 r15

,这为我解决了这个问题:

ant all clean emma debug install test

但我不确定您是否有同样的问题。

我无权访问此手机上的数据

它是未 root 的设备吗?请注意,构建表示:

WARNING: Code Coverage is currently only supported on the emulator and rooted devices.

也许您无法仅通过更改覆盖文件的位置来解决此限制。它可以在虚拟设备上运行吗?

I ran into this issue after updating my SDK to r16: Emma code coverage not working in r15 of tools

and this fixed it for me:

ant all clean emma debug install test

But I am unsure if you have the same problem.

I don't have permission to access data/data on this phone

Is it a non-rooted device? Note that the build says:

WARNING: Code Coverage is currently only supported on the emulator and rooted devices.

Maybe you can't work around this limitation by just changing the location of the coverage file. Does it work on a virtual device?

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