Wednesday, October 1, 2008

Using Emma to Improve Testing Coverage

When I was given this project the current coverage was at ~80%. As some point while working on it, eclipse was giving me errors on certain lines of code. Even after undoing the code back to the original it was still giving me the errors. It turns out that the project required that I went to Project->Clean in order to discard build problems.

Code Changes

In TestClearStack.java I added a line to test getTop(). I had issues with the isEmpty method until I found out that I had to test both true and false cases. For TestStack.java I added a test for toString. I had some difficulty parsing what was supposed to be outputted so I used a println to check. Then I added a test for the top method in case it threw a EmptyStackException.

Conclusion

I think that these changes improved the testing of the code. It's good to know that every line of code works as it's suppose to. It doesn't make a code foolproof though cause there can be elements in a program that one might not think of testing. 100% percent coverage may mean that you touch upon every line of code but it might not consider necessary features that might be missing or incidents that might cause errors.

You can find my build here.

No comments: