Skip to main content
  1. Posts/

Using Expected Exceptions in UnitTests

Sometimes, reviewing code, I see misunderstanding of using Expected Exception concept in unit tests.

Let’s consider following test class:

There are two test methods here and only first one is not correct. When service throws SomeException, Mockito.verifyZeroInteraction(bar) is not invoked, although expected exception is catched and test framework reports test passed.

The Rule of Thumb is: You may use ExpectedException only if call of the method under test is the last operator of test method.