Monday, February 19, 2007

Eclipse Code Coverage with EclEmma

It's really great to see (via the Eclipse Awards) that someone has taken the time to integrate a free coverage tool with Eclipse: EclEmma.

I've used Emma before, but hadn't followed the recent development that sees it well-integrated with the IDE. Frankly, this was the one thing that really made the commercial offerings (e.g. Clover) attractive still, so now that Emma has taken this step, there's less reason to look elsewhere.

This, to me, feels like a great model for addressing test coverage -- right in the tool you use to write the code and the unit tests. Gives you a great capability to write tests, check coverage, and write a bit more.

Even more impressive, it seems as if EclEmma can also support loading coverage results from an external launch. So, for instance, if your nightly build ran a long project-wide coverage with Emma, it seems as if you'd be able to take the results of that coverage run, fire up EclEmma and see the results.

I'll be testing this out soon.


Geoffrey Wiseman said...

So far, so good. Easily installed and tested. There's a few things I'd like to see changed:

I'd like to be able to filter in the coverage view; if I'm working with a single test, I already know that mos of the project isn't covered, but I'd like to be able to see the coverage of one or two classes that the test does hit.

Also, if all your eclipse compiled class files go into the same directory, you can instrument all or none. It'd be nice to be able to instrument subsets. For instance, I don't want to know the coverage of my unit tests. There's a workaround, but I'd rather not change my project/eclipse configuration significantly to use the tool.

That doesn't stop me from enjoying what's already there; this is a nice addition to the toolbox.

Willie Wheeler said...

As you note, there is a way to instrument subsets, though I wouldn't myself characterize it as a workaround. You need to configure your build path so that your source folders have different output folders. On the Java Build Path pane, select the Source tab and make sure that "Allow output folders for source folders" is checked. Then go to your src-test (or whatever) folder and expand it. You should see "Output folder: ..." Select that and choose edit, and override the default by changing it to classes-test or something like that. That should do it. Minor change and one that probably makes sense anyway, even without EclEmma.

Alok said...

A nice article. Lot of information. I have a small problem, though. I plugged in EclEmma to Eclipse and it works fine for stand alone applications. How does it work for web applications?

Geoffrey Wiseman said...

Well, in the simplest scenario it's basically the same -- if you have unit tests that exercise the code, you simply run these to validate code coverage.

Now if you want to verify the coverage of web templates (e.g. JSPs) or of acceptance tests running against an application in-container, that's another story. I don't know a great solution to either of those, although it might be possible to use coverage tools for in-container coverage (although I've never tried).

Ambuja said...

I am a new user of EclEMMA.It is really a nice tool.
Can anyone help me resolving the following issues?(it may sound as silly questions to you)
1)I am working on an existing framework. My code uses the Out of the box code as well.In simpler terms my source code is dependent on the framework base code which exists in a differnt project in the eclipse workspace.How can see the coverage of my code? Although I am able to view the coverage of my Unit tester as 100% but my source code coverage is shown as 0%.I am facing this issue even my sourcecode and testers are in same or different projects.
2)How can I go for instumentation of classes and kindly let me know the advantages of this?

It would be great if someone can come forward to help me out.

Anonymous said...


i use EclEmma, its great. But i have a problem by exporting the report. The wizard show that it complete but i cant see any report.

Im looking forward for Helps.