Saturday, 20 August 2016

EMMA is an open-source toolkit for measuring and reporting Java code coverage. EMMA distinguishes itself from other tools by going after a unique feature combination: support for large-scale enterprise software development while keeping individual developer's work fast and iterative.Every developer on your team can now get code coverage for free and they can get it fast!

How to Use It in server deployed build - 

Please follow bellow given steps to get code coverage for a project deployed in Apache Tomcat using emma code coverage tool - 
  • Download emma.jar and copy it to JAVA_HOME\jre\lib\ext folder (Inside JDK)
  • Deploy your war file in tomcat webapps folder and start tomcat
  • Create jarlist.txt manually with the path of tomcat deployed web application classes folder, whose code coverage you want
    • Eg. - If you have a webapplication project folder WebsiteManagement inside webapps folder of tomcat, then mention the directory path of class files package folder to which you want to cover. if you want to cover whole project then give the path upto this WebsiteManagement folder i.e. root folder. Here I am taking example of whole application coverage so path is like - 





  • Copy jarlist.txt into JAVA_HOME\jre\lib\ext folder (Inside JDK)
  • Run following command inside JAVA_HOME\jre\lib\ext folder, which will instrument classes given in jarlist.txt file
          java -cp emma.jar emma instr -m overwrite -cp @jarlist.txt
  • After the execution of above command coverage.em file will get generate inside JAVA_HOME\jre\lib\ext folder
  • Go through your application in browser, tomcat will show log - 
           EMMA: collecting runtime coverage data...  



  • Stop server. this will generate coverage.ec file inside bin folder of tomcat.

  • Now go inside JAVA_HOME\jre\lib\ext folder and execute following command - 
          java -cp emma.jar emma report -r html -sp {source path to java files of project} -in               coverage.em,{Path to tomcat bin folder}/coverage.ec

Eg – I created a eclipse project named WebsiteManagement and deployed its war file in tomcat then after performing above given operations I excuted following command in this step - 

java -cp emma.jar emma report -r html -sp C:/Users/avator/Desktop/atul_workspace/WebsiteManagement/src -in coverage.em,C:/apache-tomcat-7.0.54/bin/coverage.ec

So here in above command “source path to java files of project” is -  src folder path of project

  • The coverage code reports files will get generate at folder JAVA_HOME\jre\lib\ext\coverage.


  • Inside coverage folder you will get index.html file from there you can navigate to your coverage report-

Eg. - Coverage Reports -