Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 602
Eddified Avatar asked Sep 05 '25 05:09

Eddified


1 Answers

  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.
like image 51
Dhruv Naik Avatar answered Sep 07 '25 21:09

Dhruv Naik