views:

106

answers:

3

I have written JUnit tests for my class, and would like it to tell me if there is any part of my code that is not unit tested. Is there a way to do this?

+4  A: 

You need some code coverage tools. See here (http://java-source.net/open-source/code-coverage) for some

If you look at the first one I think it does what you need

Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage. It is based on jcoverage. Features of Cobertura:

  • Can be executed from ant or from the command line.
Preet Sangha
+11  A: 

Yes, coverage tools like cobertura or emma.

They create reports that show every line in the source code and whether it was executed or not (and aggregated statistics as well).

Of course, they can only show you if the code was run. There is no way to tell if the unit test contained assertions to confirm that the result was correct.

Thilo
+1  A: 

If you use Eclipse, you can also try EclEmma, which shows you which lines of source were covered by your test. This is sometimes more useful than running a coverage tool like Cobertura because you can run a single test from inside Eclipse and then get immediate feedback on what was covered.

Ken Liu
Thank you. I like that it easily integrates into Eclipse
chustar