Emma does not generate coverage.ec

天大地大妈咪最大 提交于 2019-12-04 14:47:05
Enfant Terrible

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~

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!