DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Get Coverage Data for Standalone Server with Cobertura


Prerequisites

Copy cobertura.jar (1.9.1), asm-3.0.jar, asm-tree-3.0.jar, jakarta-oro-2.0.8.jar, log4j-1.2.15.jar totally 5 jars to a folder (in this case it is: "/home/lichao/apps/coberturaLib").

If using cobertura-2.0.3, copy cobertura.jar and all jars in folder "lib" to "coberturaLib".

The current working directory is project home folder, under which there are 3 folders: cmd, conf, lib.

Instrument

Now we need instrument class files under "class" folder to "instru" folder:

java -cp "/home/lichao/apps/coberturaLib/*" net.sourceforge.cobertura.instrument.Main --destination instru class

Note the double quotes of "/home.../coberturaLib/*" is necessary.

If you use cobertura-2.0.3, add project dependencies ($PROJ_HOME/lib), too:

java -cp "/home/lichao/apps/coberturaLib/*:../lib/*" net.sourceforge.cobertura.instrument.Main --destination CalcServer --datafile CalcServer/cobertura.ser CalcServer.jar

Synopsis:

java -cp <Cobertura_lib> net.sourceforge.cobertura.instrument.Main --destination <dest_folder> --datafile <datafile_path> <target>

If is a folder containing class files, instrumented class files will be created under . If is a jar file, instrumented jar file will be created under . If "--destination is not specified, the instrumented one will overwrite the origin.

Start Server

This step equals to "unit test" in junit-cobertura scenario. The start.sh is:

1
2
3
4
#!/bin/sh 
CoberturaJar="/home/lichao/apps/coberturaLib/cobertura-2.0.3.jar" 
JARS="$CoberturaJar:conf:./*:lib/*" 
java -cp $JARS -Dnet.sourceforge.cobertura.datafile=cobertura.ser com.boco.deploy.Main

Note: The instrumented jar must be add before uninstrumented jar in classpath.

Synopsis:

java -cp <cobertura.jar_path>:<other_dependencies> -Dnet.sourceforge.cobertura.datafile=<datafile_path> Server.Main.Class.Name

Merge Datafile

java -cp "coberturaLib-2.0.3/*" net.sourceforge.cobertura.merge.Main --datafile GcpCollector/cmd/cobertura.ser GcpServerCore/cmd/cobertura.ser cobertura.ser

Get Report

java -cp "/home/lichao/apps/coberturaLib/*" net.sourceforge.cobertura.reporting.Main --datafile cobertura.ser --destination ../report ../../src

The report data will not be written to report files until the server process is down.

Synopsis:

java -cp <cobertura_lib> net.sourceforge.cobertura.reporting.Main --datafile <datafile_path> --destination <report_path> <source_folder>


Published

Sep 2, 2013

Last Updated

Sep 2, 2013

Category

Tech

Tags

  • cobertura 6

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor