Summary

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:

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']
}