Monday, August 13, 2007

How to justify that your code is stable !

Have you ever wondered how much tested your code is ? We often write Unit Tests to ensure proper functionality of a product. But how do you ensure that the Unit Tests actually covers most of the functionality. Well the solution to this problem is a open source tool named Cobertura. This is for Java freaks only. Cobertura is a tool which calculates the code coverage of your project.

A sample report generated by the tool :

Detailed report on the lines covered by the unit tests written for the project:

Feature List :
[This feature list is quoted from official cobertura page : ]

  1. Can be executed from ant or from the command line.
  2. Instruments Java bytecode after it has been compiled.
  3. Can generate reports in HTML or XML.
  4. Shows the percentage of lines and branches covered for each class, each package, and for the overall project.
  5. Shows the McCabe cyclomatic code complexity of each class, and the average cyclomatic code complexity for each package, and for the overall product.
  6. Can sort HTML results by class name, percent of lines covered, percent of branches covered, etc. And can sort in ascending or decending order.
The integration of this tool is very straight forward. They have given the ant script which when added to your projects ant will automatically have this integrated with your project. So simply go to the following link and digg more on how to integrate :

I am sure Java lovers will find it great and indeed a nice tool through which you can justify that your code is stable and it RoCks. :) Enjoy !.

- Reza


Shams said...

Just remember to back your code coverage report with exhaustive Test cases. Code coverage by themselves cannot be the sole indicator of stable and working code :).

Z said...

This seem to be a pretty interesting tool. It's really good to have some real numerical data on how much code has been covered rather than pretty much hunching up to your boss with some stupid percentages :P.
But then again, mere code coverage doesn't warrant the non-existence of logical errors, as shams pointed out. So everything seems right to me except for the title :).

Munaz said...

It's really nice that you brought up few of the possible good points of this open source project here in your blog which is really impressive!

Nothing offensive but being curious i would like to ask - In which context are you defining the word "Code is Stable!"? How and When we could call that my Code is Stable?

Is there any way i could expect a new post on that? :)

Salene said...

Great work.