Jacoco converting coverage.ec to reports without coverage.em

二次信任 提交于 2019-11-30 08:51:16

问题


I was able to get the code coverage report by following the steps below,

  1. Enable coverage on the build type you want (e.g. debug)

    buildTypes { debug { testCoverageEnabled true } }

  2. Apply Jacoco plugin and set version

    apply plugin: 'jacoco' jacoco { version "0.7.1.201405082137" }

  3. Run

    ./gradlew createDebugCoverageReport

  4. All the tests in connectedAndroidTest are run and coverage report is generated based on them. I can find the coverage reports in

    app/build/outputs/reports/coverage/{buildType}/index.html

and a coverage.ec file in

app/build/outputs/code-coverage/connected/coverage.ec

But no jacoco.exec since I am running from Android Instrumentation instead of Robolectric test cases.

And when I run the instrumentation from ADB ( I guess this is still using Emma ) as follows, I get a coverage.ec file as follows,

$ adb shell am instrument -w -e coverage true -e coverageFile /sdcard/coverage.ec com.sample.helloworld.test/.Runner
....
OK (4 tests)

Generated code coverage data to /sdcard/coverage.ec

But I am not able to convert the coverage.ec to report using emma since the coverage.em file is missing,

java -cp ~/adt-bundle-mac-x86_64-20130729/sdk/tools/lib/emma_device.jar emma report -r html -in \
coverage.em,myFile.ec,myapp_coverage1.ec -sp /path/to/myapp/src

Is there a way around this problem??


回答1:


Simply use the "coverage.ec" as the ".exec" file, it's worked for me

This is what Google did in Android Gradle Plugin source code.

public static final String FILE_COVERAGE_EC = "coverage.ec";

in SimpleTestCallable.java under com.android.builder.internal.testing package.




回答2:


I wrote an article about the same scenario and my solution. You can read it here. For answering this specific question you should do the following steps: Change gradle to this:

apply plugin: 'jacoco'
jacoco {
   toolVersion = '0.7.5.201505241946'
}

Second download this jar. Continue with the things you did until you have coverage.ec file. Then when you have it run:

java -jar android-jacoco-the-missing.jar -f /path/to/coverage.ec -p ./path/to/android/project

And thats it! The jar will generate a folder with the code coverage.

Another option is to use the coverage.ec with the Jenkins Jacoco plugin. But for that you need to have Jenkins set on.




回答3:


Remove . from following command its work for me

java -jar android-jacoco-the-missing.jar -f /path/to/coverage.ec -p /path/to/android/project



回答4:


To get the coverage out of coverage.ec file just rename it to coverage.exec and the open it with "Show coverage data" option

"Show coverage data" can be found under "Analyze" option in Android Studio.

Verified this with Android Studio 3.3



来源:https://stackoverflow.com/questions/29039751/jacoco-converting-coverage-ec-to-reports-without-coverage-em

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