views:

757

answers:

3

I just started using Eclipse so go easy on me ;). But when trying to debug a JUnit test case I get a dialog that states the the source is not found when I get to this line in the code in my test method:

Assert.assertEquals(1, contents.size());

I know I should probably go and try and download the source from somewhere, but I really don't want to because I have no interest in stepping into the JUnit code. I have the JUnit runtime jar so Why does Eclipse expect me to have all the referenced tools source code in order to debug my own code (seems somewhat silly)?

My main question is though, how can I tell Eclipse to skip this dialog when the source is not available and allow me to continue to debug my own code?

[Edit]

I've isolated the cause of this. It seems that Eclipse seems to think it needs the source when an exception is thrown by the internal JUnit code. In general is there anyway to tell it that it doesn't and just have it throw up an error dialog of some kind instead?

+1  A: 

Calculate contents.size() on a separate line instead or set a breakpoint on the method.

Also note the junit view in Eclipse allows you to navigate the stack trace.

Thorbjørn Ravn Andersen
+3  A: 

The debug callstack will display a JUnit source code line when throwing an exception.
But you should not need to worry about that, if you do not have the source code of JUnit.

If you go back one line in the callstack, you should see the line (of your source code) which has caused the JUnit exception.
That should be enough to debug your code.


To associate the source with JUnit, you could add the junit.jar in the librairies of your project, and associates the junit-x.y.z-src.jar to the junit-x.y.z.jar, like so:

alt text

That will generate in the .classpath of your project a line like:

<classpathentry kind="lib" path="junit-x.y.z.jar" sourcepath="junit-x.y.z-src.jar">

Note: actually, there would be the full path of the junit[...].jar files in this classpathentry line. But you could also use Linked resources to avoid that fixed value (the full path) in your .classpath file.

VonC
Thanks, that's helpful, but it doesn't solve the issue with Eclipse, and why it feels it needs to ask for source. I was able to reproduce this same behavior with Hibernate it threw an internal exception and again Eclipse is asking for source. I feel like I missing something really simple in my IDE configuration.
James
+1 for your effort. But what about the next library I use? suppose I don't always have the source then what? It seems the IDE should have a provision for not attempting to ask for it if it's not there.
James
@James: I see your point and do not think there is an eclipse option for making it *not* asking for sources. But again, you often need to focus only on your code and not on libraries you do not have the sources. Or you have those sources and can associate them easily enough with said libraries.
VonC
+3  A: 

I had this very annoying problem for a long time but was finally able to solve it. In my case, a null pointer exception was being thrown somewhere in Java's Transformer.IsRuntimeCode(ProtectionDomain) function.

I didn't really need to know about this since the exception was being caught and handled, but eclipse would pause debugging every time this happened and tell me that the source wasn't available. As a result, I constantly had to keep pressing the button to continue code execution.

In order to prevent this from happening, I:

  1. Clicked on the "Breakpoints" window at the bottom of the debugging screen
  2. Right clicked "NullPointerException"
  3. Unchecked "Caught"

This prevented the debugger from pausing program flow during a caught NullPointerException.

alt text

DutrowLLC
Good suggestion. +1
VonC