h1. Cobertura test coverage

This module for the Play! framework provides a plugin to support the Cobertura test coverage tool.

Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage.

See "http://cobertura.sourceforge.net/":http://cobertura.sourceforge.net/ for more information.

Let's see a simple usage example.

h2. <a>Enable the Cobertura module for the application</a>

In the **/conf/application.conf** file, enable the Cobertura module by adding this line:

bc. # The cobertura test coverage module
%test.play.tmp=none 
%test.module.cobertura=${play.path}/modules/cobertura
%test.cobertura.silent=false

Overriding play.tmp because Cobertura need clean class file for works.
This plugin is intended for use in the 'test' mode, and will silently do nothing in other modes. Therefore, leaving it activated while running your application in other modes is not a problem.

silent properties is for switch in manual mode.

h2. <a>Run your tests</a>

Run your tests as normal, for example:

bc. $ play test

or 

bc. $ play auto-test

and go to "/path/to/your/application/@cobertura":/path/to/your/application/@cobertura for generate new report or reset previous. And now you can watch html report in iframe or directly on "file:/path/to/your/application/test-result/code-coverage/":file:/path/to/your/application/test-result/code-coverage/. 

Code coverage is directly calculated when running the tests - each test you run will add coverage to your Java files. So at this step, it is important to run all the tests you want to analyze coverage for.

h2. <a>Continuous integration</a>

Now more interesing usage is to pluf cobertura with Continuous integration tools, such as "Hudson":http://hudson.dev.java.net/, can often use Cobertura results to graph the test coverage. For this purpose, the Cobertura module also generates an XML format report, in *test-result/code-coverage/coverage.xml*.

For switch in this mode you can delete properties %test.cobertura.silent or switch them to true. Now cobertura will generate an HTML report automatically in a directory named *test-result/code-coverage/* in your project home where your shutdown the server.  

H2. <a> 

h2. <a>Admire the results !</a>

bc. [...] INFO  - Cobertura plugin: generating test coverage report
[...]
[...] INFO  - Test coverage report has been generated: file:/path/to/test-result/code-coverage/index.html

The module will output the URL to view this report on the console. You can view this in your web browser, with a URL like this: "file:/path/to/your/application/test-result/code-coverage/":file:/path/to/your/application/test-result/code-coverage/.

!images/cobertura1!


