I am trying to setup test coverage with jacoco but I've been unsuccessful so far.
In my build.gradle I have added:
apply plugin: 'jacoco'
(...)
buildTypes {
debug {
testCoverageEnabled true
}
(...)
task jacocoTestReport(type: JacocoReport, dependsOn: "test<MyFlavor>DebugUnitTest") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
reports {
xml.enabled = true
html.enabled = true
}
def fileFilter = []
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: project.projectDir, includes:
['**/*.exec' , '**/*.ec'])
}
Then I run the JaCoCo test report with the following code:
./gradlew clean create<MyFlavor>DebugCoverageReport jacocoTestReport
I see that the unit tests are run successfully, but when I open the test report, located in:
<project>/build/reports/jacoco/jacocoTestReport/html/index.html
the report seems to be empty, as coverage is reported as N/A and not even the project packages are displayed.
Moreover, if I try to open the coverage file at
<project>/build/jacoco/test<MyFlavor>DebugUnitTest.exec
using Android Studio, all classes report 0.0% coverage.
I am using gradle 3.0.1
What am I doing wrong? Does this have something to do with the usage of flavors?