Is it possible to generate a single Cobertura report for my Grails app which includes coverage for not only the app code but also several plugins that I've written myself?
For the time being I've (improperly) written tests for my plugins in my Grails app, instead of putting those tests inside their corresponding plugins.
The report only includes my Grails app's code (domain classes, services, etc) and nothing else. I want coverage for most of the plugins that my app is using.
I've tried including the plugins via inplace notation (grails.plugin.location.fooplugin = 'path') but the coverage report still does not include my fooplugin's code.
Help?
http://grails.org/plugin/code-coverage
The plugin doesn't seem to support this behavior. I had to download the source and create a custom version for myself.
I have successfully instrumented and reported on all my Grails app's direct plugins and also its transitive plugins.
You'll need to modify the code-coverage's _Events.groovy in a few places to get things to work.
INSTRUMENTATION
Modify AntInstrumentationBuildfileBuilder.build(). It uses a MarkupBuilder to build the Ant XML which runs Cobertura. I added the below 'extraClassesDir':
File extraClassesDir = new File('/path/to/grails/project/target/work/plugin-classes')
...
'target'(name: 'instrument') {
'cobertura-instrument'(instrumentArguments) {
'fileset'(dir: "${classesDir.absolutePath}") {
'include'(name: "**/*.class")
codeCoverageExclusionList.each { pattern ->
'exclude'(name: "${pattern}")
}
}
// My additions:
'fileset'(dir: extraClassesDir.absolutePath) {
'include'(name: "**/*.class")
codeCoverageExclusionList.each { pattern ->
'exclude'(name: "${pattern}")
}
}
}
}
REPORTING
The above will instrument your classes but in the report you won't be able to jump to the source code. I modified createCoverageReports() by adding the following:
if (buildConfig.coverage?.grailsSourceInclusions) {
buildConfig.coverage.grailsSourceInclusions.each {
fileset(dir: "${it}/grails-app/controllers", erroronmissingdir: false)
fileset(dir: "${it}/grails-app/domain", erroronmissingdir: false)
fileset(dir: "${it}/grails-app/services", erroronmissingdir: false)
fileset(dir: "${it}/grails-app/taglib", erroronmissingdir: false)
fileset(dir: "${it}/grails-app/utils", erroronmissingdir: false)
fileset(dir: "${it}/src/groovy", erroronmissingdir: false)
fileset(dir: "${it}/src/java", erroronmissingdir: false)
}
}
Basically for reporting I created a new config setting, so my Grails project's BuildConfig.groovy looks like:
coverage {
enabledByDefault = false
xml = true
grailsSourceInclusions = [
'/path/to/source/of/plugin1',
'/path/to/source/of/plugin2'
]
}
ANT XML
In code-coverage's _Events.groovy, if you comment out the following line you can at least view the Ant XML that gets generated:
println "instrumentBuildFile=$instrumentBuildFile
//instrumentBuildFile.delete()
And if you did things right your XML should contain something like the following near the bottom in order to get instrumentation working:
<target name="instrument">
<cobertura-instrument datafile="/path/to/grails/project/cobertura.ser">
<fileset dir="/path/to/grails/project/target/classes">
<include name="**/*.class" />
<exclude name="**/*BootStrap*" />
<exclude name="Config*" />
<exclude name="BuildConfig*" />
...
</fileset>
<!-- Here's our addition -->
<fileset dir="/path/to/grails/project/target/work/plugin-classes">
<include name="**/*.class" />
<exclude name="**/*BootStrap*" />
<exclude name="Config*" />
<exclude name="BuildConfig*" />
...
</fileset>
</cobertura-instrument>
</target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With