Archive for the ‘Code coverage Tools’ Category

Cobertura – FAQ

Q: Where does the name “Cobertura” come from?

A: “Cobertura” is the Spanish and Portuguese word for “coverage.”
We were trying to avoid acronyms and coffee references.
It’s not too hard to associate the word “cobertura” with the word “coverage,”
and it even has a bit of a zesty kick to it!

Q: Why should I use Cobertura instead of one of the other code coverage tools?

A: We think Cobertura produces the prettiest output.
Pretty output means it’s easy to read. Easy to read means you waste less time figuring out
where to add test coverage. We also think Cobertura is easy to get running.

Q: What about Emma?

A: We haven’t used it very much, but it looks like it does a pretty good job.
Judging from the sample on the Emma web page, we think the Cobertura HTML reports
are a bit easier to digest. It looks like Emma has some nice usability features,
such as the ability to instrument all classes in a jar file with one command.
A little friendly competition never hurt anyone

Q: What do I need to use Cobertura?

A: Cobertura should work on any platform with with Java 5 or newer.
The Cobertura download packages include all the dependencies you’ll need (ASM, log4j, etc.)
Q: What is code complexity and why should I care about it?
A: McCabe’s cyclomatic code complexity algorithm is used to determine how “complex” a given piece of code is. As code becomes more complex, it becomes more error prone. If a class has a high complexity number, then that class is a good target for additional test coverage.
Q: Why is Cobertura causing me to have classpath conflicts with ASM?
A:Cobertura uses ASM to modify your bytecode. There are a few other popular programs that use ASM; Groovy and Hibernate, to name two.
You could have problems if Cobertura uses a different version of asm and you add both versions to your classpath.
Cobertura only uses ASM when instrumenting. Cobertura does not need ASM in your classpath when running tests.
If you’re seeing classpath conflicts, just make sure the asm jar that comes with Cobertura is used only by Cobertura, and only when instrumenting.

  • When I generate coverage reports, why do they always show 100% coverage everywhere?
  • When I generate coverage reports, why do they always show 0% coverage everywhere?
  • Cobertura is probably using the wrong .ser file when generating the reports.
  • When you instrument your classes, Cobertura generates a .ser file containing basic information about each class.
  • As your tests run, Cobertura adds additional information to this same data file.
  • If the instrumented classes can not find the data file when running then they will create a new one.
  • It is important that you use the same cobertura.ser file when instrumenting, running, and generating reports.
  • The best way to do this is to specify the location of the data file when running your tests.

You should pass the -Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser sysproperty to the JUnit task

These are main steps to be used for Cobertura Reports.

  1. First Download Cobertura 1.9.2 jar and put in your local file system and extract it.
  1. Then create jars( lib, bridge, ejb ) for your project using Ant or eclipse.
  2. Copy these src jars into your cobertura folder ( example : D:\Cobertura\cobertura-1.9.2\ )
  3. Instrument the project jars using
  1. cobertura-instrument.bat <path to lib jar> <path to lib_bridge jar> <path to EJB jar>
  1. All the project jars would now be instrumented with the cobertura code along with the creation of cobertura.ser file in the same directory.
  2. Then deploy the jars in your development server.
  3. You should also add the cobertura.jar in the classpath(BE,FE/IN depending on your project’s nature).
  4. Copy the cobertura.ser to the server and in the startManagedWebLogic.sh, add the below system property
  1. -Dnet.sourceforge.cobertura.datafile=${directory where you have copied the cobertura.ser}/cobertura.ser
  1. Fire your Selenium test cases either through Firefox(Selenium IDE) or using Selenium Remote Control. Or else run your application by manually
  2. Shutdown the development server using WL Admin console and copy the cobertura.ser file back to the local cobertura folder.
  3. Run the cobertura report using
  1. cobertura-report.bat –destination <Output folder for reports> <List down the source folders(lib,lib_bridge,ejb) separated by ;>

9. Now you can check your local folder output folder Index.jsp


Read Full Post »