This is the second post on Java code coverage with Emma. In previous post, we discussed about Code Coverage and introduction to Emma. In this post, we will discuss about how to install Emma and do the basic code coverage with an example and screenshots. After you complete the reading of this post and previous post, you should be able to download Emma, install it and run Emma from command line. Towards the end, we will also discuss about how to get HTML report and interpret simple Emma report. It will be good if you can download Emma from here and use it side by side as you read this post. Please make sure that you download the binary of Emma and not the source version. The binary version of Emma should be sufficient to do this. Along with this, you need to have Java compiler and Java Runtime Environment to compile your Java classes. In order to give a picture of how Emma works and process involved, let us take the toughest approach of running Emma from command line rather than integrating with IDE. In later posts, we will discuss about IDE integration (Eclipse/Netbeans) to make developers life easier.
Downloading and Installing Emma
Emma comes in three different versions - binaries with examples, source and libraries. In order to do this example, we need to download "binaries with examples and documentation". You can directly download it form Sourceforge.net or you can access Sourceforge project via Emma home page. Irrespective of the way you choose, please make sure that you download Emma binaries with example version. After downloading emma.
GreaterTestDriver.java
Greater.java
Running Emma and Getting output in text file
Emma with HTML Reporting
Emma Reporting with Source Code
# In order to run Emma from command line and to get report in test file
java -cp emma.jar emmarun -cp . example.GreaterTestDriver
# In order to run Emma from command line and get report in HTML but without Source Code
java -cp emma.jar emmarun -r html -cp . example.GreaterTestDriver
# In order to run Emma from command line, get report in HTML and merge the result with Source Code
java -cp emma.jar emmarun -sp . -r html -cp . example.GreaterTestDrive