How to set up Jacoco tests for espresso on Android

I have a library project with some weird configuration between modules. Due to some specific limitations, I now have 3 modules: core (main module), core-test (where my unit tests are) and core-app (where my espresso tests are).

At this time, I need to create a coverage report so that it is available on the CI server. Using properties such as additionalSourceDirsand additionalClassDirs, I created a custom task to include core classes in the resulting file jacoco.exec. But for Espresso tests, I cannot find a way to configure this, since the jacoco node configuration on the Android Gradle plugin seems no options for anything . Inclusion testCoverageEnabledfor a specific assembly configuration works, it generates coverage, but only for classes in the kernel application (I know that in a normal project this is the expected behavior), so the coverage.ecfile does not have runtime data for my other classes.

Does anyone know a way to add more classes / sources to the coverage task for integration tests? (perhaps expanding in AndroidJUnitRunnerany way or changing the task itself through Groovy?)

+4
source share
1 answer

You need to add the following to your build.gradle:

apply plugin: 'jacoco'
jacoco {
    toolVersion "0.7.5.201505241946"
}

Also in buildTypes:

debug {
    testCoverageEnabled = true

Run

gradle tasks 

and you will see a task named (if you use a debug build to cover)

createDebugCoverageReport

Run

gradle createDebugCoverageReport

In the next folder you will see cover.ec

$build_dir/outputs/code-coverage/connected/flavors/debug/coverage.ec

Which device are you using and which OS? Some device with a specific OS creates an empty coverage area. Com. Share additional information about the OS and the device you are using?

0
source

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


All Articles