Sunday, February 1, 2009

About Cobertura


Reference URL: http://cobertura.sourceforge.net/
http://mojo.codehaus.org/cobertura-maven-plugin/index.html
Download SRC: http://cobertura.sourceforge.net/download.html

About Coberture

If you've ever written unit test cases for any program language, you know how important it is to ensure that your test cases execute each line of code. This is called code coverage. The more your unit test cases exercise the logic in your application code, the less likely it is that a bug slips through your unit test cases. On a large code base (common to most applications these days), it's hard to judge how effectively your coverage statistics. There are various tools to help quantitatively measure the coverage of your unit test cases. Such vendor tools that accomplish this are Parasoft's JTest, and Quest's JProbe. But who wants to buy software? I've been trying out this open source code coverage measurement tool called Cobertura. So far I've only been using the ant tasks in combination with HTML reports. The reports it produces are really nice and informative, even allowing you to drill down into each class such that you can view the source and actually see the number of times each line of code was called from your test suite. Alternatively, red highlighting will call those lines with no coverage to your attention. There's also a command line interface if you choose to execute it outside of your build. Check it out here:

http://cobertura.sourceforge.net/


What is Cobertura?

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.


Features

* Can be executed from ant or from the command line.
* Instruments Java bytecode after it has been compiled.
* Can generate reports in HTML or XML.
* Shows the percentage of lines and branches covered for each class, each package, and for the overall project.
* Shows the McCabe cyclomatic code complexity of each class, and the average cyclomatic code complexity for each package, and for the overall product.
* Can sort HTML results by class name, percent of lines covered, percent of branches covered, etc. And can sort in ascending or decending order.

Sample Report



Example: Steps to How to configure Cobertura

Download

No comments: