Test Code Coverage Plugin

  • Tags: testing, coverage, grails2.4
  • Latest: 2.0.3-2
  • Last Updated: 16 August 2014
  • Grails version: 1.3 > *
12 votes

15% of Grails users

Dependency:
test ":code-coverage:2.0.3-2"

 Documentation  Source  Issues

Summary

Creates Code Coverage reports for your code

Description

Test Code Coverage Plugin

This plugin will generate code coverage reports using Cobertura.

Currently Grails Forked mode is not supported.

To run:

grails test-app -coverage

Command line options:

By default, the script will create HTML reports and place them in the tests/report/cobertura directory. If you would prefer XML reports (e.g for a Continuous Integration server), specify the -xml flag like this:

grails test-app -coverage -xml

The plugin does some post processing on the HTML reports to make the Controller action names appear in human readable form (like Controller.list instead of Controller.$_closure1 ). If you don't require this or it is too resource intensive, you can tell the plugin to skip post processing of HTML files by passing the -nopost flag.

grails test-app -coverage -nopost

To force coverage to run (if you have set the enabledByDefault flag to false; see configuration options for details) you can turn it back on for a single test run using the folling command line option:

grails test-app -coverage

If you have the default configured to run coverage every time, you can override it using the -nocoverage flag on the command line:

grails test-app -nocoverage

For Maven users who would like to define utilize the -nopost and -xml flags but can't from the command line, they can be defined in BuildConfig.groovy:

coverage {
   nopost = true
   xml = true
}

Configuration Options:

If you want to disable coverage by default, you can set the enabledByDefault config attribute equal to false
coverage {
   enabledByDefault = false
}

You can add your own exclusions from the reports by adding an entry in your BuildConfig.groovy file like this:

coverage {
   exclusions = ["**/ExcludedController*", "**/excludedDir/**"]
}

The exclusions are by class name, and package, not path. Here's some more examples, that will filter out jsecurity classes and richui classes, if you are running cobertura with webtest.:

//cobertura exclusions
coverage {
   exclusions = [
      '**/de/andreasschmitt/richui/taglib/renderer/**',
      '**/plugins/richui-0.4/src/groovy/de/andreasschmitt/richui/**',
      '**/de/andreasschmitt/richui/image/**',
      '**/org/jsecurity/**',
      '**/org/jsecurity/grails/**',
      '**/JsecDbRealm*',
      '**/*TagLib*/**',
      "**/*Tests*",
      '**/JsecAuthBase*',
      '**/JsecurityFilters*']
}

By default, the plugin excludes several items from the coverage results including:

"**/*BootStrap*",
"Config*",
"**/*DataSource*",
"**/*resources*",
"**/*UrlMappings*",
"**/*Tests*",
"**/grails/test/**",
"**/org/codehaus/groovy/grails/**",
"**/PreInit*",
"*GrailsPlugin*"

As of version 1.1.4, you can completely override the default list of exclusions and provide your own.

coverage {
   exclusionListOverride = [
      "**/grails/test/**",
      "*GrailsPlugin*"]
}

In addition, you can add directories to the default list for source files to include in the coverage reports. For example, if you're using the Jsecurity plugin and want to see the source for files in the 'realms' directory in the reports, add the following to your BuildConfig.groovy:

coverage {
   // list of directories to search for source to include in coverage reports
   sourceInclusions = ['grails-app/realms']
}