Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break on Exception in Eclipse using jUnit

Is there a way to make Eclipse break on uncaught exceptions while in debug mode for jUnit? Eclipse breaks fine when executing main(). Is there a command-line switch I can use?

Thanks

like image 566
User1 Avatar asked Jul 14 '09 14:07

User1


People also ask

How do you set breakpoints in JUnit?

To set a breakpoint, Right-click and choose Toggle breakpoint. To Debug the JUnit Test, use the below option: Right Click >> Debug As >> Junit Test.

How do I fix Java exception breakpoint in Eclipse?

You can fix this immediately by opening the Markers view and delete the Java Exception Breakpoints. However, to permanently remove this type of breakpoints, you have to go to the Java Debug options and uncheck the "Suspend excecution on uncaught exceptions" option.

How do I create a break point in Eclipse?

To define a breakpoint in your source code, right-click in the left margin in the Java editor and select Toggle Breakpoint. Alternatively, you can double-click on this position. The Breakpoints view allows you to delete and deactivate Breakpoints and modify their properties.


2 Answers

From the debug perspective you can filter exactly which exceptions you are interested in.

In the Breakpoints view there is a "J!" button. This opens a window that allows you to choose which exceptions you want to break on.

If the problem only occurs when JUnit tests you need to make sure you are launching the tests in debug mode. The Rerun button in the JUnit will run in "normal" mode. To run the tests in debug you can right click on the file and select "Debug as -> JUnit Test" from the menu.

like image 181
Aaron Avatar answered Sep 20 '22 15:09

Aaron


If you run in debug mode, this should be the default behaviour of later versions of Eclipse.

like image 45
Thorbjørn Ravn Andersen Avatar answered Sep 18 '22 15:09

Thorbjørn Ravn Andersen