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

Posted by Uri on Stack Overflow See other posts from Stack Overflow or by Uri
Published on 2010-05-06T17:13:43Z Indexed on 2010/05/06 17:18 UTC
Read the original article Hit count: 175

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about junit