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:
What version of Grails are you using here?
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.
Posta un commento