【发布时间】:2019-09-13 20:05:48
【问题描述】:
我在与使用 Matchers 的测试不同的测试中得到 InvalidUseOfMatchersException
以下两个测试单独运行良好,但一起运行时,第一个测试成功通过后,第二个测试失败并抛出 InvalidUseOfMatchersException 指向第一个测试
@Test(expected = InputException.class)
public void shouldThrowExceptionWhenInputNull() {
calculator.calculateA(any(), any(), any(),eq(null));
}
@Test
public void testCalculateB() {
assertTrue(BigDecimal.valueOf(8000).compareTo(calculator.calculateB(12)) == 0);
}
这是堆栈跟踪中的异常
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Misplaced or misused argument matcher detected here:
TestClass.shouldThrowExceptionWhenInputNull
根据异常,第一次测试应该失败但它通过了,第二次测试失败了。这两项测试均成功通过
【问题讨论】:
标签: junit mockito spring-test