我只想出于教育目的测试在Mockito中的滥用异常,以证明该错误:
@Test
public void testNotAMockException() {
try {
List<String> list = new ArrayList<String>();
Mockito.doReturn(100).when(list).size();
fail("Should have thrown a NotAMockException because list is not a mock!");
} catch (NotAMockException e) {
assertThat(e.getMessage(), containsString("Argument passed to when() is not a mock!"));
}
}
这行为正确,并且断言通过,但是随后测试失败,并显示org.mockito.exceptions.misusing.UnfinishedStubbingException
我知道为什么,但是有什么方法可以抑制最后由Mockito触发的TestFailue?
谢谢