How to Debug JUnit tests similar to a regular Java program within Eclipse
Double click set breakpoint
Use Debug mode to run in Eclipse
Hover on that line of code, and then click step over
or f6
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:
- set exception breakpoint to stop when
NullPointerException
is thrown - use the exception's stack trace reported by JUnit and set the breakpoint on the line that throws the exception (that's the one I prefer).
- Open the Junit test case or Junit Test Suite you want to run.
- Place your Break Point.
- Right Click on the File and click on Debug As > Junit Test.