Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force JUnit to fail on ANY unchecked exception, even if swallowed

I am using JUnit to write some higher level tests for legacy code that does not have unit tests.

Much of this code "swallows" a variety of unchecked exceptions like NullPointerExceptions (e.g., by just printing stack trace and returning null). Therefore the unit test can pass even through there is a cascade of disasters at various points in the lower level code.

Is there any way to have a test fail on the first unchecked exception even if they are swallowed?

The only alternative I can think of is to write a custom JUnit wrapper that redirects System.err and then analyzes the output for exceptions.

like image 571
Uri Avatar asked May 06 '10 17:05

Uri


1 Answers

If you execute the tests in your IDE's debugger you can configure the IDE to break when an exception is thrown.

like image 100
Nathan Hughes Avatar answered Sep 21 '22 00:09

Nathan Hughes