Rake construction is successful only if the coverage check passes

I am working on a grails application. We use cobertura to generate code coverage reports. Now I want to change the grails project, so the build should fail if the code coverage is less than 90%. How can I achieve this in the grail?

+5
source share
1 answer

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) .

+4

All Articles