How to Debug JUnit tests similar to a regular Java program within Eclipse

  1. Double click set breakpoint

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

  1. Open the Junit test case or Junit Test Suite you want to run.
  2. Place your Break Point.
  3. Right Click on the File and click on Debug As > Junit Test.