Last active
January 3, 2018 10:51
-
-
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
This file contains hidden or 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
// 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") | |
} |
This file contains hidden or 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
// 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