gpt4 book ai didi

junit - jUnit中的ExpectedException?

转载 作者:行者123 更新时间:2023-12-04 05:11:08 24 4
gpt4 key购买 nike

jUnit中是否有等效于NUnit的ExpectedException或Assert.Throws <>?

最佳答案

junit4:

@Test(expected = org.dom4j.DocumentException.class)
void shouldThrowException() {
getFile(null);
}

junit3:
void testShouldThrowException() {
try {
getFile(null);
fail("Expected Exception DocumentException");
} catch(DocumentException e) {}
}

关于junit - jUnit中的ExpectedException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1052683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com