JUnit 4.13 中已弃用的 ExpectedException.none() 的替代方案
Alternatives to the deprecated ExpectedException.none() in JUnit 4.13
我正在尝试将 @Rule
注释与 ExpectedException
一起使用
用于初始化 ExceptedException 变量类型的 ExceptedException.none() 方法表示它已被弃用 初始化 ExceptedException 对象的替代方法是什么。
示例:
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 示例:
我正在尝试将 @Rule
注释与 ExpectedException
用于初始化 ExceptedException 变量类型的 ExceptedException.none() 方法表示它已被弃用 初始化 ExceptedException 对象的替代方法是什么。 示例:
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 示例: