Question

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.

Was it helpful?

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)

OTHER TIPS

What you're asking about is called "coverage". There are several tools that measure that, some of which integrate into Eclipse. I've used jcoverage and it works (I believe it has a free trial period, after which you'd have to buy it). I've not used it, but you might also try Coverlipse.

If I understand the question correctly you want more than the standard stacktrace data but you don't want to manually instrument your code with, say, log4j debug statements.

The only thing I can think of is to add some sort of bytecode tracing. Refer to Instrumenting Java bytecode. The article references Cobertura which I haven't used but sounds like what you need...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top