JUnit, Mockito

How to use @Rule annotation instead of the expected keyword to unit test exceptions

The usual way for unit testing expected exceptions looks like this: @Test(expected = ConfigurationException.class) It has although the following disadvantages: you can not check details of the exception, like message or cause you can not do anything with the exception It is a better solution to use theĀ @Rule annotation from JUnit. import org.hamcrest.core.StringContains; import org.junit.Assert;… Continue reading How to use @Rule annotation instead of the expected keyword to unit test exceptions