Reputation: 304
I have been trying to use the new code coverage feature in Android Studio 1.2. There seems to be no documentation for the feature, but so far I figured out to add
testCoverageEnabled true
to the debug flavor of my Gradle file.
Still I can only create code coverage reports for JUnit test cases, not instrumented Android test cases.
Is there any way to generate code coverage for instrumented android test cases ?
Upvotes: 10
Views: 3371
Reputation: 9
As @Phil H noted, you need to add the jacoco plugin in order to generate reports, and you need to run the connectedCheck in order to run the tests that generate the data. You can find a post here: new link: https://medium.com/@rafael_toledo/setting-up-an-unified-coverage-report-in-android-with-jacoco-robolectric-and-espresso-ffe239aaf3fa with additional details.
Upvotes: 0
Reputation: 388
In the project build.gradle file (root/build.gradle) add url "https://plugins.gradle.org/m2/"
under the buildscript > repositories sections. In my project is looks like this:
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
The plugin can be applied in the project build.gradle or (as in my case) to the specific module's build.gradle (module/build.gradle):
apply plugin: 'com.vanniktech.android.junit.jacoco'
Apply the plugin at the very top of the build script before you enter the android
section.
From the Terminal run:
Windows
gradlew.bat connectedCheck
Linux (other)
./gradlew connectedCheck
References:
https://plugins.gradle.org/plugin/com.vanniktech.android.junit.jacoco https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/
Upvotes: 1