JaCoCo shows 0% coverage, even all tests had passed

ⅰ亾dé卋堺 提交于 2019-12-23 14:20:47

问题


  1. I have written some test cases under androidTest directory.
  2. I am using androidx (testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner")
  3. added dependencies:

    androidTestImplementation 'androidx.test:runner:1.1.0'

    androidTestImplementation 'androidx.test:rules:1.1.0'

  4. added JaCoCo as dependency, as well.

  5. When I run createDebugAndroidTestCoverageReport Gradle task, all the test cases run successfully but coverage is 0% in report

I am guessing that is due to this error:

V/InstrumentationResultParser: Error: Failed to generate Emma/JaCoCo coverage. V/InstrumentationResultParser: INSTRUMENTATION_CODE: -1


回答1:


A custom version of the androidx.test.runner.AndroidJUnitRunner is most likely not required.

But this path here, which you've defined as the debugTree:

"${project.buildDir}/intermediates/classes/debug"

Might meanwhile be something alike:

"${project.buildDir}/intermediates/javac/debug/compileDebugJavaWithJavac/classes"

for example:

build/intermediates/javac/debug/compileDebugJavaWithJavac/classes
build/intermediates/javac/release/compileReleaseJavaWithJavac/classes

If it cannot find the *.class files, the test-coverage will be reported as 0%.

Just browse the build directory to see what the actual path is.



来源:https://stackoverflow.com/questions/55575418/jacoco-shows-0-coverage-even-all-tests-had-passed

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