nAdd parameter to @Test annotation, indicating that a particular class of exception is expected to
occur during the
test.
n
n@Test(expected=ExceptedTypeOfException.class)
npublic void testException()
n{
n
exceptionCausingMethod();
n}
nIf no exception is thrown, or an unexpected
exception occurs, the
test will fail.
nThat is, reaching the end of the method with
no exception will
cause a test case failure.
nTesting contents of the exception message, or
limiting the scope
of where the exception is expected requires using the approach on the next slide.