I don’t think that the code coverage plugin supports this directly, but it’s easy enough to do this by connecting to a powerful graphing event infrastructure. Putting this in your own scripts/_Events.groovy, the assembly will fail if the coverage is below a certain threshold:
eventStatusFinal = { message ->
if (message ==~ /.*Cobertura Code Coverage Complete.*/) {
def report = new XmlSlurper().parse(new File("target/test-reports/cobertura/coverage.xml"))
if (Float.parseFloat(report.'@line-rate'.text()) < 0.90) {
throw new RuntimeException("coverage too low!")
}
}
}
This requires that you enable XML report generation with this parameter in grails-app/conf/BuildConfig.groovy:
coverage {
xml = true
}
(line-rate, branch-rate) .