如何断言在JUnit 4测试中抛出某个异常?
如何使用JUnit 4来习惯地测试某些代码抛出异常?
我当然可以这样做:
@Testpublic void testFooThrowsIndexOutOfBoundsException() { boolean thrown = false; try { foo.doStuff(); } catch (IndexOutOfBoundsException e) { thrown = true; } assertTrue(thrown);}
我记得有注释或Assert.xyz或某物对于这类情况,这要少得多,更多的是JUnit的精神。
胡子哥哥
米琪卡哇伊
相关分类