Skip to content
Gradle plugin that creates JaCoCo test reports for Android unit tests
Branch: master
Clone or download
friederbluemle and arturdm Update build plugins
- axion-release 1.10.0
- artifactory 4.9.3
Latest commit bb6404b Mar 4, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea Added project stub Aug 31, 2015
gradle/wrapper Fix gradle 5.0 support Feb 25, 2019
src Fix gradle 5.0 support Feb 25, 2019
.gitignore Update dependencies (#53) Feb 24, 2019
.travis.yml Fix release deployment Feb 25, 2019
LICENSE Initial commit Aug 31, 2015
README.md Fix release deployment Feb 25, 2019
build.gradle Update build plugins Mar 9, 2019
gradle.properties Update usage and simplify code Feb 24, 2019
gradlew Fix gradle 5.0 support Feb 25, 2019
gradlew.bat Fix gradle 5.0 support Feb 25, 2019
settings.gradle Update usage and simplify code Feb 24, 2019

README.md

jacoco-android-gradle-plugin

Build Status codecov Download

A Gradle plugin that adds fully configured JacocoReport tasks for unit tests of each Android application and library project variant.

Why

In order to generate JaCoCo unit test coverage reports for Android projects you need to create JacocoReport tasks and configure them by providing paths to source code, execution data and compiled classes. It can be troublesome since Android projects can have different flavors and build types thus requiring additional paths to be set. This plugin provides those tasks already configured for you.

Usage

buildscript {
  repositories {
    ...
    jcenter()
  }
  dependencies {
    ...
    classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4'
  }
}

apply plugin: 'com.android.application'
apply plugin: 'jacoco-android'

jacoco {
  toolVersion = "0.8.3"
}

tasks.withType(Test) {
  jacoco.includeNoLocationClasses = true
}

android {
  ...
  productFlavors {
    free {}
    paid {}
  }
}

The above configuration creates a JacocoReport task for each variant and an additional jacocoTestReport task that runs all of them.

jacocoTestPaidDebugUnitTestReport
jacocoTestFreeDebugUnitTestReport
jacocoTestPaidReleaseUnitTestReport
jacocoTestFreeReleaseUnitTestReport
jacocoTestReport

The plugin excludes Android generated classes from report generation by default. You can use jacocoAndroidUnitTestReport extension to add other exclusion patterns if needed.

jacocoAndroidUnitTestReport {
  excludes += ['**/AutoValue_*.*',
              '**/*JavascriptBridge.class']
}

You can also toggle report generation by type using the extension.

jacocoAndroidUnitTestReport {
  csv.enabled false
  html.enabled true
  xml.enabled true
}

To generate all reports run:

$ ./gradlew jacocoTestReport

Reports for each variant are available at $buildDir/reports/jacoco in separate subdirectories, e.g. build/reports/jacoco/jacocoTestPaidDebugUnitTestReport.

Examples

Snapshot usage

Snapshots of the development version are available in JFrog's snapshots repository.

buildscript {
  repositories {
    ...
    maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local' }
  }
  dependencies {
    ...
    classpath 'com.dicedmelon.gradle:jacoco-android:x.y.z-SNAPSHOT'
  }
}

License

Copyright 2015 Artur Stępniewski

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You can’t perform that action at this time.