Exceptions in JUnit Tests

When an exception is thrown in a unit test, the unit test will fail, giving a red bar - unless there is a try/catch that catches the exception and swallows it quietly. 

Therefore, you should make sure that catching an exception in a unit test is indeed what you really mean to do. 

Should the test really handle the error and continue, perhaps succeeding, or should the test fail, giving a visual indication that something went wrong?

I'd add that when the right behavior of a test case is a thrown Exception, one should add to the @TEST annotation one's expectation. 
e.g. @Test(expected = NumberFormatException.class)


Popular posts from this blog

Profiling Java @ 2019

Ant Explorer graphical Ant build tool

Shared/Pro/Managed Hosting for your site - which to choose ? (NO AFFILIATE LINKS!)