mercoledì 11 maggio 2011

Having a Jenkins Grails build agains a war and code coverage reports

Recently I've read Luke Daley's post about testing Grails apps against a war and Christian Oestreich's post regarding Jenkins builds and code reports, so I tried to merge their knowledge and get a Jenkins build with tests against war AND code reports.

After struggling with various configurations (and erroneously blaming geb for not having my functional tests working) it turned out that you can't have code coverage if its target is a war: cobertura jar must be included in your war file or you'll encounter a ClassNotFoundException.

Having cobertura jars in production builds is not an acceptable solution, so I've ended including the dependency inside an environment check in project's BuildConfig.groovy:

// Including cobertura jar (testing against a war, special case)  
  if (grailsSettings.grailsEnv == "test"){
    def args = System.getProperty("grails.cli.args")
    if (args.tokenize().containsAll(['-war','-coverage'])){
      compile('net.sourceforge.cobertura:cobertura:1.9.4.1'){
        excludes "asm", "log4j"
      }
    }
  }


Note that cobertura jar is included only if the '-war' and '-coverage' switches are passed together in the command line and environment is 'test'.

Now I can run all of my tests from Jenkins against a war build and having all code reports I need, Chuck Norris is happy, and I can go back to meditate.

3 commenti:

Unknown ha detto...

What version of Grails are you using here?

Manuel ha detto...

It's Grails 1.3.7, although I think this workaround may work as well with older versions. I suggest code coverage plugin to be updated to latest version instead, due to some issues that involve war dependecies that were resolved recently.

Manuel ha detto...
Questo commento è stato eliminato dall'autore.