Reputation: 3154
In eclipse, if I run a Java program in debug mode with no breakpoints, and if the JVM hits a NullPointerException, Eclipse will kindly highlight the offending line of code, and show the local variables, etc. Execution is paused. I can evaluate code using the Display tab, and so on.
But, if I run a JUnit test in debug mode, and the jvm hits a NullPointerException, the jvm does not pause, and I don't have a chance to see the local variables.
Is it possible to run JUnit tests so that the JVM will pause automatically when I hit a NullPointerException, without using breakpoints?
Edit: Using JUnit 4 & Juno
Upvotes: 29
Views: 74102
Reputation:
Eclipse stops when the exception that's thrown is uncaught and would bump you out of main(). However, when you run with JUnit framework, all exceptions are caught by JUnit, so Eclipse does not stop.
Two solutions come to mind:
NullPointerException
is thrownUpvotes: 8
Reputation: 121
Upvotes: 12
Reputation: 718
Double click set breakpoint
Use Debug mode to run in Eclipse
Hover on that line of code, and then click step over
or f6
Upvotes: 3
Reputation: 1046
You can see it on JUnit tab, if you double-click on the line that has a problem, you'll go to the location where the null-pointer exception happened.
java.lang.NullPointerException <--First line of the error
at.com.myProject.MyClass.myMethod(MyClass.java:theLineOfMyCode) <-- the line that you should double-click
After you do this, you will be redirected to the line of the error.
Upvotes: 0