Skip to content

Instantly share code, notes, and snippets.

@mfebrianto
Last active March 3, 2023 07:48
Show Gist options
  • Save mfebrianto/1a55c22ebadd33111c21f256617e9df1 to your computer and use it in GitHub Desktop.
Save mfebrianto/1a55c22ebadd33111c21f256617e9df1 to your computer and use it in GitHub Desktop.
apply plugin: 'jacoco'
android {
debug {
// this line will add new task createDebugCoverageReport that needed by jacoco
// however as default it will generate coverage for androidTest
// it does not generate coverage for unitTest
testCoverageEnabled true
}
}
jacoco {
reportsDirectory = file("$buildDir/reports/coverage")
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
task jacocoCombinedTestReports(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
group = "verification"
description = "Creates JaCoCo test coverage report for Unit and Instrumented Tests on the debug"
reports {
xml.required = true
html.required = true
}
// Files to exclude:
// Generated classes, platform classes, etc.
def excludes = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*'
]
// generated classes
classDirectories.from = fileTree(
dir: "$buildDir/intermediates/classes/debug",
excludes: excludes
) + fileTree(
dir: "$buildDir/tmp/kotlin-classes/debug",
excludes: excludes
)
// sources
sourceDirectories.from = [
android.sourceSets.main.java.srcDirs,
"src/main/kotlin"
]
// Output and existing data
// Combine Unit test and Instrumented test reports
executionData.from = fileTree(dir: "$buildDir", includes: [
// Unit tests coverage data
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
// Instrumented tests coverage data
"outputs/code_coverage/debugAndroidTest/connected/*coverage.ec"
])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment