How do I write a test that fails when an unexpected exception is thrown?
Declare the exception in the throws clause of the test method and don’t catch the exception within the test method. Uncaught exceptions will cause the test to fail. The following is an example test that fails when the IndexOutOfBoundsException is raised: public void testIndexOutOfBoundsExceptionNotRaised() throws IndexOutOfBoundsException { ArrayList list = new ArrayList(10); Object o = list.