Fix Jacoco code coverage report issue
Enable your code coverage for unit tests by adding gradle hook.
Exclude auto generated code, code from library, tests classes.
Ref:
@@ -37,6 +37,10 @@ apply from: file('gradle_scripts/AndroidHelper.gradle')
jacoco {
toolVersion = "0.8.4"
}
+// Inspiration https://medium.com/@android2ee/playing-with-gradle-3-and-some-few-code-coverage-on-android-with-jacoco-47df7c9328ae
+tasks.withType(Test) {
+ jacoco.includeNoLocationClasses = true
+}
/**
* Computes a semantic version string, e.g. "1.0" or "2.5.7" by parsing git branches or tags.
* Branch name takes priority, otherwise the last annotated tag name will be used.
@@ -404,6 +408,19 @@ android {
}
}
testOptions.unitTests.includeAndroidResources = true
+ // Exclude auto generated files from the code coverage report
+ jacocoAndroidUnitTestReport {
+ excludes += ['**/R.class',
+ '**/R$*.class',
+ '**/*$ViewInjector*.*',
+ '**/BuildConfig.*',
+ '**/Manifest*.*',
+ 'android/databinding/**',
+ 'com/android/databinding/**',
+ '**/androidx/databinding/**',
+ '**/AnnotationDatabaseImpl.class' // Generated by RoboBlender
+ ]
+ }
}
sourceSets {
main {
