views:

200

answers:

3

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.

+7  A: 
VonC
+3  A: 

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.

Ian Varley
Doesn't coverage mean the union of the code that is affected by all unit tests in the system? I am looking for the result of a certain execution, not necessarily via JUnit. But I'll check it out. Thanks !
Uri
The term coverage is usually used with testing but it's the thing you are looking for. (The code coverage for a certain program execution)
Touko
+2  A: 

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...

Michael Rutherfurd