Setup jacoco coverage reporting

Change-Id: I02bc2e54723179afd921ffe7b2537e035e5906ed
pull/2/head
Alex Vanyo 3 years ago
parent 85e078298e
commit 67290500a9

@ -17,8 +17,11 @@ plugins {
id 'com.android.application' id 'com.android.application'
id 'kotlin-android' id 'kotlin-android'
id 'kotlinx-serialization' id 'kotlinx-serialization'
id 'jacoco'
} }
def jacocoTestReport = tasks.create("jacocoTestReport")
android { android {
compileSdk buildConfig.compileSdk compileSdk buildConfig.compileSdk
@ -66,6 +69,42 @@ android {
includeAndroidResources = true includeAndroidResources = true
} }
} }
androidComponents {
def coverageExclusions = [
// Android
"**/R.class",
"**/R\$*.class",
"**/BuildConfig.*",
"**/Manifest*.*"
]
onVariants(
selector().all(),
{ variant ->
def testTaskName = "test${variant.name.capitalize()}UnitTest"
def reportTask = tasks.register("jacoco${testTaskName.capitalize()}Report", JacocoReport) {
dependsOn(testTaskName)
reports {
xml.required.set(true)
html.required.set(true)
}
classDirectories.setFrom(
fileTree("$buildDir/tmp/kotlin-classes/${variant.name}") {
exclude(coverageExclusions)
}
)
sourceDirectories.setFrom(files("$projectDir/src/main/java", "$projectDir/src/main/kotlin"))
executionData.setFrom(file("$buildDir/jacoco/${testTaskName}.exec"))
}
jacocoTestReport.dependsOn(reportTask)
}
)
}
} }
dependencies { dependencies {
@ -115,3 +154,20 @@ dependencies {
} }
} }
} }
jacoco {
toolVersion libs.versions.jacoco.get()
}
tasks.withType(Test) {
jacoco {
// Required for JaCoCo + Robolectric
// https://github.com/robolectric/robolectric/issues/2230
// TODO: Consider removing if not we don't add Robolectric
setIncludeNoLocationClasses(true)
// Required for JDK 11+ with the above
// https://github.com/gradle/gradle/issues/5184#issuecomment-391982009
excludes = ["jdk.internal.*"]
}
}

@ -12,6 +12,7 @@ androidxLifecycle = "2.4.0"
androidxNavigation = "2.3.5" androidxNavigation = "2.3.5"
androidxTest = "1.4.0" androidxTest = "1.4.0"
androidxTestExt = "1.1.2" androidxTestExt = "1.1.2"
jacoco = "0.8.7"
junit4 = "4.13" junit4 = "4.13"
kotlin = "1.6.0" kotlin = "1.6.0"
kotlinxCoroutines = "1.5.2" kotlinxCoroutines = "1.5.2"

Loading…
Cancel
Save