-
-
Save gumil/98a453577d7f7e65f49ecb84c06a3082 to your computer and use it in GitHub Desktop.
Good example of the merged Jacoco code covarage Gradle configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply from: "$rootDir/coverage.gradle" | |
//... | |
android { | |
//... | |
buildTypes { | |
//... | |
debug { | |
testCoverageEnabled true //we use "debug" build type for test coverage (can be other) | |
} | |
} | |
//... | |
testOptions { | |
unitTests.returnDefaultValues = true | |
unitTests.all { | |
jacoco { | |
includeNoLocationClasses = true | |
} | |
} | |
} | |
//... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'jacoco' | |
/** | |
* The correct path of the report is $rootProjectDir/app/build/reports/jacoco/index.html | |
* to run this task use: ./gradlew clean jacocoTestReport | |
*/ | |
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) { //we use "debug" build type for test coverage (can be other) | |
group = "reporting" | |
description = "Generate unified Jacoco code coverage report" | |
reports { | |
xml.enabled = false | |
html.enabled = true | |
csv.enabled = false | |
xml.destination = "${buildDir}/reports/jacocoTestReport.xml" | |
html.destination = "${buildDir}/reports/jacoco" | |
csv.destination = "${buildDir}/reports/jacocoTestReport.csv" | |
} | |
def fileFilter = [ | |
'**/*Test*.*', | |
'**/AutoValue_*.*', | |
'**/*JavascriptBridge.class', | |
'**/R.class', | |
'**/R$*.class', | |
'**/Manifest*.*', | |
'android/**/*.*', | |
'**/BuildConfig.*', | |
'**/*$ViewBinder*.*', | |
'**/*$ViewInjector*.*', | |
'**/Lambda$*.class', | |
'**/Lambda.class', | |
'**/*Lambda.class', | |
'**/*Lambda*.class', | |
'**/*$InjectAdapter.class', | |
'**/*$ModuleAdapter.class', | |
'**/*$ViewInjector*.class', | |
'**/*_MembersInjector.class', //Dagger2 generated code | |
'*/*_MembersInjector*.*', //Dagger2 generated code | |
'**/*_*Factory*.*', //Dagger2 generated code | |
'*/*Component*.*', //Dagger2 generated code | |
'**/*Module*.*' //Dagger2 generated code | |
] | |
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter) //we use "debug" build type for test coverage (can be other) | |
def mainSrc = "${project.projectDir}/src/main/java" | |
sourceDirectories = files([mainSrc]) | |
classDirectories = files([debugTree]) | |
executionData = fileTree(dir: "$buildDir", includes: [ | |
"jacoco/testDebugUnitTest.exec", //we use "debug" build type for test coverage (can be other) | |
"outputs/code-coverage/connected/*coverage.ec" | |
]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment