问题
- I have written some test cases under
androidTest
directory. - I am using androidx (
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
) added dependencies:
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
added JaCoCo as dependency, as well.
- 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