Cover Your Bases

Software Engineering Done Right — s01e03

Code Coverage — The Theoretical

Coverage as a metric for quality

Coverage as a KPI

By the numbers

Covering up bugs

Code Coverage — The Practical

apply plugin: "jacoco"
jacoco {
toolVersion = "0.8.5"
}

jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.destination file("${buildDir}/reports/jacocoHtml")
}
}

test {
jacoco {
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
includes= ["com.arc_e_tect.*"]
classDumpDir = file("$buildDir/jacoco/classpathdumps")
}
}
test {
jacoco {
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
includes= ["com.arc_e_tect.*"]
classDumpDir = file("$buildDir/jacoco/classpathdumps")
}

finalizedBy jacocoTestReport
// create a report every time we test our application.
}
Phonebook JaCoCo Code Coverage report
package com.arc_e_tect.blog.phonebook;

public class App {
public String getGreeting() {
return "Hello Arc-E-Tect.";
}

public static void main(String[] args) {
// System.out.println(new App().getGreeting());
}
}
Phonebook JaCoCo Code Coverage report
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.6
}
}
}
}
// to run coverage verification during the build (and fail when appropriate)
check.dependsOn jacocoTestCoverageVerification
> Task :jacocoTestCoverageVerification FAILED
[ant:jacocoReport] Rule violated for bundle Phonebook: instructions covered ratio is 0.4, but expected minimum is 0.6
FAILURE: Build failed with an exception.* What went wrong:
Execution failed for task ':jacocoTestCoverageVerification'.
> Rule violated for bundle Phonebook: instructions covered ratio is 0.4, but expected minimum is 0.6
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.orgBUILD FAILED in 3s
9 actionable tasks: 9 executed

Coverage as an indicator of confidence

Concluding

Disclaimer

Credits

Some people see things and ask ‘Why?’ I dream of things and ask ‘Why not?’

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store