

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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?

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
Thank you. I like that it easily integrates into Eclipse – chustar Mar 30 '10 at 14:14

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.

share|improve this answer

You need some code coverage tools. See here ( for some

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


  • Can be executed from ant or from the command line.
share|improve this answer

Your headline and your actual question differ. The tools mentioned in the other answers can tell you, which part of the code were not tested (=not executed at all). Making "make sure that all parts of code is unit tested" is a different thing. The coverage tools can tell you whether all lines/instructions have been executed, but they don't guarantee that everything is tested functionally (all constellations of data, all execution paths, etc.). This requires some brain power. In my opinion, test coverage often gives a wrong feeling of safety. E.g. testing trivial getters increases coverage a lot but is rather useless.

share|improve this answer

If you are using IntelliJ then there is a button titled

"Run With Coverage"

Run with Coverage

share|improve this answer

Your Answer


