Enforce 90% Coverage¶
Copy-paste configuration to enforce 90% coverage on all new code.
Basic Configuration¶
plugins {
id("io.github.gw-kit.delta-coverage") version "3.6.0"
}
configure<io.github.surpsg.deltacoverage.gradle.DeltaCoverageConfiguration> {
diffSource.git.compareWith("refs/remotes/origin/main")
reportViews {
val test by getting {
violationRules.failIfCoverageLessThan(0.9)
}
}
}
With HTML Reports¶
configure<io.github.surpsg.deltacoverage.gradle.DeltaCoverageConfiguration> {
diffSource.git.compareWith("refs/remotes/origin/main")
reports {
html.set(true)
}
reportViews {
val test by getting {
violationRules.failIfCoverageLessThan(0.9)
}
}
}
With Generated Code Exclusions¶
configure<io.github.surpsg.deltacoverage.gradle.DeltaCoverageConfiguration> {
diffSource.git.compareWith("refs/remotes/origin/main")
excludeClasses.value(
listOf(
"**/generated/**/*.*",
"**/*\$\$*.class"
)
)
reportViews {
val test by getting {
violationRules.failIfCoverageLessThan(0.9)
}
}
}
With Branch Threshold¶
Branches are often harder to cover. Use a lower threshold with entity count:
configure<io.github.surpsg.deltacoverage.gradle.DeltaCoverageConfiguration> {
diffSource.git.compareWith("refs/remotes/origin/main")
reportViews {
val test by getting {
violationRules {
failOnViolation.set(true)
rule(CoverageEntity.LINE) {
minCoverageRatio.set(0.9)
}
rule(CoverageEntity.INSTRUCTION) {
minCoverageRatio.set(0.9)
}
rule(CoverageEntity.BRANCH) {
minCoverageRatio.set(0.8)
entityCountThreshold.set(5) // Ignore if < 5 branches
}
}
}
}
}
Run¶
Expected Output¶
Passing¶
+----------------------+----------+----------+--------+
| [test] Delta Coverage Stats |
+----------------------+----------+----------+--------+
| Class | Lines | Branches | Instr. |
+----------------------+----------+----------+--------|
| com.example.Feature | 95% | 90% | 94% |
+----------------------+----------+----------+--------+
| Total | ✔ 95% | ✔ 90% | ✔ 94% |
+----------------------+----------+----------+--------+
| Min expected | 90% | 90% | 90% |
+----------------------+----------+----------+--------+
BUILD SUCCESSFUL