Created
December 16, 2018 17:09
-
-
Save gmazzo/86a365c11bc92eb59c963dada03f960f to your computer and use it in GitHub Desktop.
Jacoco script for Android unit and instrumentation tests coverage report, supporting Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'jacoco' | |
jacoco { | |
toolVersion = '0.8.2' | |
} | |
android { | |
buildTypes { | |
debug { | |
testCoverageEnabled = true | |
} | |
} | |
testOptions.unitTests.all { | |
jacoco { | |
includeNoLocationClasses = true | |
} | |
} | |
} | |
task jacocoTestReport { self -> | |
build.dependsOn self | |
} | |
// based on https://proandroiddev.com/unified-code-coverage-for-android-revisited-44789c9b722f and https://github.com/nomisRev/AndroidGradleJacoco | |
android.testVariants.all { | |
def variant = it.testedVariant | |
def name = variant.name.capitalize() | |
tasks.create(name: "jacoco${name}TestReport", type: JacocoReport) { self -> | |
group = 'Reporting' | |
description = "Generates Jacoco coverage reports on the ${variant.name} variant" | |
reports { | |
xml.enabled = true | |
html.enabled = true | |
} | |
sourceDirectories = files(variant.sourceSets.collectMany({ it.java.source })) | |
classDirectories = fileTree(dir: buildDir, includes: [ | |
"intermediates/classes/${variant.name}/**", | |
"tmp/kotlin-classes/${variant.name}/**" | |
], excludes: [ | |
'android/**/*.*', | |
'**/R.class', | |
'**/R$*.class', | |
'**/BuildConfig.*', | |
'**/Manifest*.*', | |
'**/*Test*.*', | |
'**/*Module.*', // modules for Dagger. | |
'**/*Module$Companion.*', // modules for Dagger+Kotlin. | |
'**/*Dagger*.*', // Dagger auto-generated code. | |
'**/*MembersInjector*.*', // Dagger auto-generated code. | |
'**/*_Provide*Factory*.*', | |
'**/*_Factory.*', // Dagger auto-generated code | |
]) | |
executionData = fileTree(dir: buildDir, includes: [ | |
"jacoco/test${name}UnitTest.exec", | |
'outputs/code-coverage/connected/*coverage.ec' | |
]) | |
doLast { | |
println "Wrote HTML coverage report to ${reports.html.destination}/index.html" | |
println "Wrote XML coverage report to ${reports.xml.destination}" | |
} | |
dependsOn "test${name}UnitTest", "create${name}CoverageReport" | |
jacocoTestReport.dependsOn self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
But seems that this wont include androidUnitTests, so in out put I can just see unit tests result. Do you have any thought?