Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JaCoCo shows 0% coverage, even all tests had passed

  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

like image 358
Subhan Avatar asked Apr 08 '19 14:04

Subhan


1 Answers

Google just redirected me to my own answer ...

As it turned out, for Android projects one (meanwhile) has to use a path alike this:

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

In case you may wonder... JaCoCo only works for @RunWith(JUnit4.class) Java unit tests in test (but not @RunWith(AndroidJUnit4.class) Android integration tests in androidTest).

like image 88
Martin Zeitler Avatar answered Oct 16 '22 15:10

Martin Zeitler