How to get coverage for an Android project using Espresso tests

I used to write Android tests using Robotium and retrieve coverage using Emma.

I recently switched to using Espresso tests, and I'm having trouble getting Instrumentation test coverage. I can only get coverage for unit tests that use Robolectric. I am currently using gradle and Jacoco for this. The best tutorial I found that helped me get to this point: https://blog.gouline.net/2015/06/23/code-coverage-on-android-with-jacoco/

Can I get coverage for Espresso tests using Android hardware?

+4
source share
1 answer

The android gradle plugin has a built-in function.

Just set the parameter to a testCoverageEnabledvalue truein the file build.gradle:

android {
   buildTypes {
      debug {
         testCoverageEnabled = true
      }
   }
}

Then use:

./gradlew connectedCheck

or

./gradlew createDebugCoverageReport

It issues a test report in the module directory:

/build/outputs/reports/coverage/debug/

Just open index.html

Example:

enter image description here

+14
source

Source: https://habr.com/ru/post/1613506/


All Articles