我正在尝试使用 @Rule
带有 ExpectedException
的注释
异常异常.none() 初始化ExceptionedException 变量类型的方法表示不推荐使用哪些替代方法来初始化ExceptionedException 的对象。
例子:
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testThrownException() throws Exception {
expectedException.expect(CustomException.class);
expectedException.expectMessage("Exception Message");
...
}
最佳答案
你读了吗the deprecation notice ?
Deprecated. Since 4.13
Assert.assertThrows
can be used to verify that your code throws a specific exception.
见 this answer例如:
关于java - JUnit 4.13 中已弃用的 ExpectedException.none() 的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62355427/