Run time code coverage using Emma

Emma is a free java code coverage tool which measures and reports code coverage of java based products. The most important and usable factor of Emma is, its ability to measure code coverage during the application runtime. At WSO2, we have been searching for a tool to get QA test coverage of our middleware products. Automated QA tests are executed against the binary products. Therefore, source level unit test coverage does not help to identify the figures of QA test coverage. Emma was the best tool which satisfied our requirements.

The procedure is quite simple. Suppose you are going to get the coverage of a binary which obviously contains hundred of jars. First, you need to prepare a list of jars which requires to be instrumented. The list can be prepared easily in *nix environments as follows.

xargs -n 1 $JAVA_HOME/jre/bin/java -cp emma.jar emma instr -m overwrite -cp < jarlist.txt

This inserts tracking code to the jars listed in jarlist.txt.

Now, you should restart your application and Emma starts to gather coverage data. If you have an automated functional test suite, run it over the instrumented binary or test the product manually.


After completing the testing, stop your application. Now, we need to generate the coverage report. Issue the following command.

java -cp emma.jar emma report -r html -in coverage.em,coverage.ec

This generates an html report as shown below.





Currently, we are in the process of developing a selenium based automation framework and we use this test coverage mechanism to find out the components which require more tests.

Comments

Unknown said…
How would i go about this solution in a Windows environment? Can I utilize this with a single .WAR?
Heath Gerhardt said…
The solution is almost identical in windows. It's all Java after all. The only difference I can see is the command he used to execute the instrumentation.
indrasenareddy said…
coverage.ec is not generating. I am trying my application in tomcat.

I have done the following steps:
1. I have deployed my application in tomcat
2.i have copied emma.jar to C:\Program Files\Java\jre1.5.0_21\bin\lib\ext

3. My tomcat5w.exe, contain the following info:
JVM as: C:\Program Files\Java\jre1.5.0_21\bin\client\jvm.dll
Java Options:
-Demma.coverage.out.file=D:\Tomcat 5.5\emma\coverage.ec
-Demma.coverage.out.merge=true

4. Now i have instrumented the deployed application as below.
java -cp emmar.jar emmae instr -m overwrite -cp "D:\Tomcat 5.5\webapps\ROOT\WEB-INF\classes\com"
and coverage.em has generated in C:\Program Files\Java\jre1.5.0_21

5.Now i have started my tomcat and did some transaction.
when i see in stdout.logs ,i am getting
EMMA: collecting runtime coverage data ...

EMMA: runtime controller started on port [47653]

6.Stopped the tomcat
7.i tried to find coverage.ec in D:\Tomcat 5.5\bin
and also in C:\Program Files\Java\jre1.5.0_21\

but i could not found this file.

8.And also tried the application to run from command line prompt,there also i couldnot found the file.

9.i also set my jre path java_home in environment variables

Popular posts from this blog

Working with HTTP multipart requests in soapUI

Common mistakes to avoid in WSO2 ESB - 1 - "org.apache.axis2.AxisFault: The system cannot infer the transport information from the URL"

How to deploy JSR181 annotated class in Apache Axis2