How do I write a test that passes when an expected exception is thrown?
Catch the exception within the test method. If it isn’t thrown, call the fail() method to signal the failure of the test. The following is an example test that passes when the expected IndexOutOfBoundsException is raised: public void testIndexOutOfBoundsException() { ArrayList list = new ArrayList(10); try { Object o = list.