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
1 comment:
Hi there, I try your example, but it didn't work... Could you pls tell me what's wrong... here is what i did...
my working directory is EmmaTest:
C:\Users\MyUser\EmmaTest>dir /b
emma.jar
Greater.class
Greater.java
GreaterTestDriver.class
GreaterTestDriver.java
C:\Users\829929\EmmaTest>java -cp emma.jar emmarun -cp . example.GreaterTestDriver
EMMA: collecting runtime coverage data ...
EMMA: runtime controller started on port [47653]
EMMA: no metadata collected at runtime [no reports generated]
[EMMA v2.1, build 5320 (stable)]
emmarun: [MAIN_CLASS_NOT_FOUND] application class [example.GreaterTestDriver] could not be loaded
Exception in thread "main" com.vladium.emma.EMMARuntimeException: [MAIN_CLASS_NOT_FOUND] application class [example.GreaterTestDriver] could not be loaded
at com.vladium.emma.run.RunProcessor._run(RunProcessor.java:473)
at com.vladium.emma.run.RunProcessor.run(RunProcessor.java:107)
at com.vladium.emma.run.runCommand.run(runCommand.java:263)
at emmarun.main(emmarun.java:27)
Caused by: java.lang.ClassNotFoundException: example.GreaterTestDriver
at com.vladium.emma.run.InstrClassLoader.findClass(InstrClassLoader.java:253)
at com.vladium.emma.run.InstrClassLoader.loadClass(InstrClassLoader.java:122)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.vladium.emma.run.RunProcessor._run(RunProcessor.java:468)
Greater.java class
package example;
public class Greater {
public void compare (int a, int b){
if ( a > b)
System.out.println(a + " is greater");
else
System.out.println(b + " is greater");
}
}
GreaterTestDriver.java class
package example;
public class GreaterTestDriver {
public static void main (String[] args){
System.out.println("Greater Test version 1");
Greater gt = new Greater();
compare(10,5);
}
}
hope to hear from you... thanks in advance
Post a Comment