Tuesday, January 08, 2008

Code Coverage for Eclipse redeux: EclEmma

In a previous entry, I lamented that I couldn't get instant feedback for the coverage results of my unit tests in eclipse. A coworker (David Koontz of SolutionsIQ) pointed me at EclEmma. In a nutshell, it works.

It gives me line-by-line coverage, highlighted in green, yellow, and red like the coverage reports I get from Cobertura. In addition to file-by-file coverage, EclEmma also summarizes coverage reports for an entire project in an Eclipse view much like the Cobertura's roll-up behavior.

It plugs into Eclipse smoothly via update site, and works with all my tests including configuration details with Spring, Hibernate, HSQL, etc. Usage was simple: if I had a JUnit execution defined in Eclipse (generated automatically via runAs .. unit test), then I can reuse it with EclEmma. Run As ... Coverage Test is also available.

My only complaint is some strange behavior around code that throws exceptions. If a block of code throws an exception partway through, EclEmma counts that entire block as untested. The authors point to this being a limitation of the Emma code coverage tool. My code doesn't generally throw a lot of expected exceptions, so it hasn't been a major issue.

In general, happy as a clam am I!