使用 junit @Rule,expectCause() 和 hamcrest matchers
2022-09-01 14:57:02
我有一个测试:
@Rule
public ExpectedException thrown = ExpectedException.none();
...
@Test
public void testMethod()
{
final String error = "error message";
Throwable expectedCause = new IllegalStateException(error);
thrown.expectCause(org.hamcrest.Matchers.<Throwable>equalTo(expectedCause));
someServiceThatTrowsException.foo();
}
当通过mvn测试方法运行时,我得到错误:
java.lang.NoSuchMethodError: org.junit.rules.ExpectedException.expectCause(Lorg/hamcrest/Matcher;)V
测试编译正常。
请帮帮我,无法理解异常的原因如何测试?