put the jacoco.gradle
file below somewhere in your app repo (like scripts
folder), and then add apply from: '../scripts/jacoco.gradle'
to your module gradle file.
This will add additional gradle build tasks to your app, in the form of "testFlavourUnitTestCoverage" that you can run manually (e.g. testStagingDebugUnitTestCoverage
) to generate the coverage.
You can edit def excludes
definition to further exclude classes you don't want to generate the coverage for. If you have source in other folders beyond those specified in def coverageSourceDirs
, add them.
This will generate both exec
file used by external code quality analyzers (like Sonarqube), in the build/jacoco
folder, and XML and HTML reports, in the build/reports/jacoco/flavourName
folder.
You can then click through the links in the report and arrive at the annotated code to see exactly which lines are not covered by tests.
Hello,
I tried your script by calling "gradlew clean testDebugUnitTestjacocoTaskReport" but in this way jacocoTaskReport isnt a valid command.
So I tried "gradlew clean testDebugUnitTest" only but it dosent generate a report.xml file. Have you any suggestions on what could happened ?
I did add "apply from: 'path/jacoco.gradle'" in my build.gradle and it syncs well.
Gradle: 4.1.3
Jacoco: 0.8.4
Thank you very much.