Code coverage in android studio 1.2 for instrumental tests

I am trying to use the new code coverage feature in Android Studio 1.2. There seems to be no documentation for this feature, but so far I have decided to add

testCoverageEnabled true 

for the debugging style of my Gradle file.

However, I can generate code coverage reports for JUnit test cases and not test files on Android.

Is there a way to generate code coverage for Android instrumental test cases?

+7
android android-studio junit gradle android-instrumentation
source share
2 answers

As @Phil H noted, you need to add the jacoco plugin to create reports, and you need to run the connected CheckCheck to run the tests that generate the data. You can find the message here: http://blog.wittchen.biz.pl/test-coverage-report-for-android-application/ with additional information.

+1
source share
  • Add .gradle repository plugin

In the project build.gradle file (root / build.gradle) add the url "https://plugins.gradle.org/m2/" in the buildscript> repositories section. In my project, it looks like this:

 buildscript { repositories { mavenCentral() jcenter() maven { url "https://plugins.gradle.org/m2/" } } 
  1. Apply jacoco plugin

The plugin can be applied in the build.gradle project or (as in my case) to a specific build.gradle module (module / build.gradle):

 apply plugin: 'com.vanniktech.android.junit.jacoco' 

Apply the plugin at the very top of the script assembly before you enter the android section.

  1. Enter if necessary .
  2. Run gradlew connectedCheck

From terminal launch:

Window

 gradlew.bat connectedCheck 

Linux (other)

 ./gradlew connectedCheck 
  1. Results will be created in /module/build/reports/androidTests/connected/index.html

Literature:

https://plugins.gradle.org/plugin/com.vanniktech.android.junit.jacoco https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/

0
source share

All Articles