sum*_*n j 6 code-coverage gradle jacoco
鉴于使用Gradle 5.0构建的多模块项目,我想使用 jacoco 强制执行所有代码覆盖率。我能够在模块级别设置覆盖强制。但是由于依赖关系的性质,许多测试都是在一个集成模块中编写的,该模块涵盖了大部分代码。因此,仅当整体代码覆盖率低于特定阈值时,我才希望构建失败。下面是我的 build.gradle,无论我为累积覆盖率设置什么值,构建都不会失败。
apply plugin: 'java'
apply plugin: 'jacoco'
subprojects {
apply plugin: 'java'
apply plugin: 'jacoco'
tasks.withType(JacocoReport).all {
reports {
html.enabled true
}
check.dependsOn it
}
jacocoTestReport {
executionData = fileTree("$buildDir/jacoco/test.exec")
subprojects.each {
sourceSets it.sourceSets.main
dependsOn it.test
}
}
jacocoTestCoverageVerification {
executionData fileTree("$buildDir/jacoco/test.exec")
violationRules {
rule {
limit {
counter = 'LINE'
minimum = 0.5 //individual module coverage level
}
failOnViolation true
}
}
}
tasks.build.dependsOn(jacocoTestReport)
tasks.build.dependsOn(jacocoTestCoverageVerification)
jacocoTestReport.mustRunAfter jacocoTestCoverageVerification
check.dependsOn jacocoTestCoverageVerification
}
//overall cumulative coverage report
task jacocoMergeTestReport(type: JacocoReport) {
executionData fileTree(project.rootDir.absolutePath).include('*/build/jacoco/*.exec')
subprojects.each {
sourceSets it.sourceSets.main
dependsOn it.test
}
reports {
html {
enabled true
destination rootProject.file("$rootProject.buildDir/reports/jacoco/html")
}
}
}
//overall cumulative coverage tasks
jacocoTestCoverageVerification {
def execFilesToInclude = subprojects.collect {
it.name+"build/jacoco/*.exec"
}
executionData fileTree(project.rootDir.absolutePath).include(execFilesToInclude)
violationRules {
rule {
element = 'CLASS'
limit {
counter = 'LINE'
minimum = 0.8 //no matter which value I set, build does not fail
}
failOnViolation true
}
}
}
tasks.build.dependsOn jacocoMergeTestReport
tasks.build.dependsOn jacocoTestCoverageVerification
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
445 次 |
最近记录: |