Search code examples
javaeclipseprofilingcode-coveragetrace

How to identify which lines of code participated in a specific execution of a Java program?


Suppose that I have a Java program within an IDE (Eclipse in this case). Suppose now that I execute the program and at some point terminate it or it ends naturally.

Is there a convenient way to determine which lines executed at least once and which ones did not (e.g., exception handling or conditions that weren't reached?)

A manual way to collect this information would be to constantly step with the debugging and maintain a set of lines where we have passed at least once. However, is there some tool or profiler that already does that?

Edit: Just for clarification: I need to be able to access this information programmatically and not necessarily from a JUnit test.


Solution

  • eclemma would be a good start: a code coverage tool would allow a coverage session to record the information you are looking for.

    alt text
    (source: eclemma.org)