Wednesday, October 1, 2008

Using Emma for Code Coverage

This is my first time using a code coverage program like Emma. Code coverage is the measure of a program code. It is a form of testing that looks at the code directly and measure if a line is being use by the program. When I started to learn and write Java Programs, I did not know there were tools for code coverage.

I was optimistic when I heard there were Java code coverage tools like Emma. Emma is a great code tool, it generates an .HTML report that I can view on a browser. Emma highlights lines that are 100% coverage green and lines that have little or no coverage red and yellow. I ran Emma on a program that involves using a stack and list. It was a pain correcting lines that was red; I had to write new code that will “use” a line that was in red. For example:


I have a method called “isEmpty()” that method checks if a object (stack, list.) is empty. If the stack is empty then it will give true, if not empty then it will give a false. Emma highlighted that method; I think it was saying that the method was not use in anyway. The solution was this:


assertTrue(“Testing stack is empty”, stack.isEmpty());


So I use the method in checking if the stack is empty, assume that it is empty.
There were lines of code that I add to satisfy Emma, and making the code 100% coverage.


Using Emma is great; it saves time in debugging. What I learn from using a code coverage tool like Emma is that it does not show all the bugs in the code. For example input and output of results, Emma say the program have 100% coverage, but the program can crash if it is not correctly use. What I like to say is that code coverage tool is like a thin protection, but it does not expose all the flaws in a program. Like Emma, it was worth using it and the other tools that help make life easier when debugging a program.

Here is my .ZIP file containing source files, and build files: http://sites.google.com/site/phillipkhlau/files/stack-klau4-v2-6.0.1001.zip

No comments: