gpt4 book ai didi

JUnit5 - ExpectedException.expectCause() 等效

转载 作者:行者123 更新时间:2023-12-03 13:37:45 25 4
gpt4 key购买 nike

最佳答案

下面是一个例子:

public class ExpectedExceptionTest {

@Test
public void shouldThrow() {
IOException exc = Assertions.assertThrows(IOException.class, this::throwing);
Assertions.assertEquals("root cause", exc.getCause().getMessage());
}

private void throwing() throws IOException {
throw new IOException(new IllegalStateException("root cause"));
}
}

就个人而言,我更喜欢 AssertJ,它具有非常详细的描述性 exception assertions .

关于JUnit5 - ExpectedException.expectCause() 等效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53432093/

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