JaCoCo
JaCoCo is a Java Code Coverage library created by EclEmma.
Using JaCoCo with Gradle
plugins {
jacoco
}
tasks.test {
finalizedBy(tasks.jacocoTestReport)
// jacocoTestReport task will always run after test task
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
xml.required.set(true
csv.required.set(true)
html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco/html"))
// above will create html reports in /build/reports/jacoco/html
}
}
jacoco {
toolVersion = "0.8.9"
reportsDirectory.set(layout.buildDirectory.dir("reports/jacoco"))
// layout.buildDirectory : /builds
}
Running test with jacoco will create binary files under build/jacoco
Reports can be generated for better visualization
- HTML file is used for local
- XML file is used for other purposes (like github action)
We can create rules to enforce certain amount of coverage
tasks.jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = "0.5"toBigDecimal()
}
}
rule {
isEnabled = false
element = "CLASS"
includes = listOf("org.gradle.*")
limit {
counter = "LINE"
value = "TOTALCOUNT"
maximum = "0.3".toBigDecimal()
}
}
}
}
enabled
whether to enable this rule (default = true)
element
the unit that we will check coverage on (default = BUNDLE)
ex) BUNDLE, CLASS, GROUP, METHOD, etc
counter
the metrics that is used to check and calculate code coverage (default = INSTRUCTION)
ex) LINE, BRANCH, CLASS, METHOD, INSTRUCTION, etc
Add JaCoCo Coverage Report in Github Actions Pipeline
- We use third party library in Github Actions marketplace.
'Java' 카테고리의 다른 글
| Collecting Data with Streams (2) (0) | 2023.11.15 |
|---|