There are a few things we should take care of when using the jacoco report, which looks like this:
Enabled test coverage in /build.gradle
android { ... buildTypes { debug { testCoverageEnabled true } ... } }
Create task for jacoco report
apply plugin: 'jacoco' task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') { reports { xml.enabled = true html.enabled = true } def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter) def mainSrc = "${project.projectDir}/src/main/java" sourceDirectories = files([mainSrc]) classDirectories = files([debugTree]) executionData = files("${buildDir}/jacoco/testDebugUnitTest.exec") }
Gradle command for jacoco report
./gradlew clean jacocoTestReport
Find jacoco report here
Created jacoco report path after jacocoTestReport successfully completed.
application / build / reports / covers / debugs / index.html
In addition, I created one of the jacoco related repositories that you can watch.
https://github.com/jiteshmohite/JacocoAndroidSample
Also, make sure you use the Gradle command inside the application directory.
Try the above sample repository for reference. I created this with zero complexity, so anyone can go and use it.
jitesh mohite
source share