Skip to content
Permalink
Browse files

Generate code coverage report (#216)

* Generate code coverage report

Enable jacoco, the official Gradle code coverage plugin.

The 'build' task will write a code coverage report to
build/reports/jacoco for each subproject that has tests.
We should consider publish periodical reports to a well known
location.

This change also defines a minimum coverage verification task.
The task is for experiment only, and is not added to the build
process yet.
  • Loading branch information...
weiminyu committed Aug 7, 2019
1 parent cf3f960 commit ce791e8b9709f3ed029c42e1eca2fec699349d17
Showing with 51 additions and 0 deletions.
  1. +2 −0 build.gradle
  2. +3 −0 config/dependency-license/allowed_licenses.json
  3. +46 −0 java_common.gradle
@@ -44,6 +44,8 @@ plugins {

id 'idea'
id 'com.diffplug.gradle.spotless' version '3.18.0'

id 'jacoco'
}

wrapper {
@@ -108,6 +108,9 @@
{
"moduleLicense": "Eclipse Public License 1.0"
},
{
"moduleLicense": "Eclipse Public License v1.0"
},
{
"moduleLicense": "Google App Engine Terms of Service"
},
@@ -17,11 +17,17 @@ apply plugin: 'nebula.lint'
apply plugin: 'net.ltgt.apt'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'

// Checkstyle should run as part of the testing task
tasks.test.dependsOn tasks.checkstyleMain
tasks.test.dependsOn tasks.checkstyleTest

// Generate per-subproject reports in build/reports/jacoco directory.
// TODO(weiminyu): publish periodical reports to well known location.
// TODO(weiminyu): investigate incremental coverage change calculation and alert.
tasks.test.finalizedBy jacocoTestReport

dependencies {
// compatibility with Java 8
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
@@ -87,3 +93,43 @@ spotless {
endWithNewline()
}
}

// Initialize for coverage minimum determination for each sub project.
task initCoverageMinimums {
// Use current coverage ratio of each subproject as placeholder value.
// Long-term plan is to calculate incremental coverage on the fly.
rootProject.ext.coverageMinimums = [
'core' : 0.6,
'proxy' : 0.52,
'util' : 0.57
].asImmutable()

rootProject.ext.getMinCoverage = { key ->
if (rootProject.ext.coverageMinimums.containsKey(key)) {
return rootProject.ext.coverageMinimums.get(key)
}
return 0.0
}
}

// Alerts for coverage violation. Note that,
// - This task is FYI only and needs to be invoked explicitly.
// - This task does not address incremental coverage.
jacocoTestCoverageVerification {

dependsOn initCoverageMinimums

violationRules {
rule {
// Each limit consists of the following properties:
// - An 'element' type: BUNDLE (default), PACKAGE, CLASS, SOURCEFILE, or METHOD.
// - A 'counter' type: INSTRUCTION (default), LINE, BRANCH, COMPLEXITY, METHOD, or CLASS
// - A 'value' type: TOTALCOUNT, COVEREDCOUNT, MISSEDCOUNT, COVEREDRATIO (default),
// or MISSEDRATIO
// - The 'minimum' threshold, given as a fraction or a percentage (including '%')
limit {
minimum = rootProject.ext.getMinCoverage(project.getName())
}
}
}
}

0 comments on commit ce791e8

Please sign in to comment.
You can’t perform that action at this time.