If you want to assert that a certain exception is thrown in JUnit 4 tests? Be careful using expected exception, because it only asserts that the method threw that exception, not a particular line of code in the test.
1 2 3 4 5 6 7 | @Test(expected = IndexOutOfBoundsException.class) public void testIndexOutOfBoundsException() { ArrayList emptyList = new ArrayList(); Object o = emptyList.get(0); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.