如何断言在JUnit 4测试中抛出某个异常?
@Testpublic void testFooThrowsIndexOutOfBoundsException() {
boolean thrown = false;
try {
foo.doStuff();
} catch (IndexOutOfBoundsException e) {
thrown = true;
}
assertTrue(thrown);}
烙印99
胡子哥哥
米琪卡哇伊
随时随地看视频慕课网APP
相关分类