Skip to content

Instantly share code, notes, and snippets.

@ahmed-basyouni
Last active January 3, 2018 10:51
Show Gist options
  • Save ahmed-basyouni/57c37713cc0838d35dc8c26533014828 to your computer and use it in GitHub Desktop.
Save ahmed-basyouni/57c37713cc0838d35dc8c26533014828 to your computer and use it in GitHub Desktop.
A gradle task that can ignore certain packages from test coverage such as models
// packages to exclude for example generated classes, R class and models package, add all packages that you wish to exclude from test coverage
def fileFilter = [
'**/models/**',
'**/*$ViewInjector*.*','**/*$ViewBinder*.*',
'**/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"
// override jacocTestReport task
task jacocoTestReport(type: JacocoReport, overwrite: true, dependsOn: 'test') {
group = "Reporting"
reports {
html.enabled = true
html.destination = "${buildDir}/reports/jacoco"
}
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = files("${buildDir}/jacoco/testDebugUnitTest.exec")
}
// define packages that you wish to exclude from sonar test coverage report here it eclude the models package and all sub packages
property "sonar.coverage.exclusions", "**/models/**/*,**/ANY_OTHER_PACKAGE/**/*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment