Jacoco将coverage.ec转换为无coverage.em的报告 [英] Jacoco converting coverage.ec to reports without coverage.em
问题描述
我可以按照以下步骤获取代码覆盖率报告,
I was able to get the code coverage report by following the steps below,
-
启用所需的构建类型的覆盖范围(例如调试)
Enable coverage on the build type you want (e.g. debug)
buildTypes {
debug {
testCoverageEnabled true
}
}
buildTypes {
debug {
testCoverageEnabled true
}
}
应用Jacoco插件并设置版本
Apply Jacoco plugin and set version
apply plugin: 'jacoco'
jacoco {
version "0.7.1.201405082137"
}
apply plugin: 'jacoco'
jacoco {
version "0.7.1.201405082137"
}
运行
./gradlew createDebugCoverageReport
connectedAndroidTest中的所有测试都将运行,并基于这些测试生成覆盖率报告.我可以在以下位置找到覆盖率报告
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
和其中的coverage.ec文件
and a coverage.ec file in
app/build/outputs/code-coverage/connected/coverage.ec
但是没有jacoco.exec,因为我是从Android Instrumentation而不是Robolectric测试用例运行的.
But no jacoco.exec since I am running from Android Instrumentation instead of Robolectric test cases.
当我按如下方式从ADB运行检测工具(我猜它仍在使用Emma)时,我得到的coverage.ec文件如下,
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
但是由于缺少coverage.em文件,因此我无法使用emma转换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??
推荐答案
只需将"coverage.ec"用作".exec"文件,即可为我工作
Simply use the "coverage.ec" as the ".exec" file, it's worked for me
这就是Google在Android Gradle Plugin源代码中所做的事情.
This is what Google did in Android Gradle Plugin source code.
公共静态最终字符串FILE_COVERAGE_EC ="coverage.ec";
public static final String FILE_COVERAGE_EC = "coverage.ec";
在com.android.builder.internal.testing包下的SimpleTestCallable.java中.
in SimpleTestCallable.java under com.android.builder.internal.testing package.
这篇关于Jacoco将coverage.ec转换为无coverage.em的报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!