当mockito当时返回间谍不工作?

时间:2018-06-05 17:52:37

标签: mockito

来自文档:Important gotcha on spying real objects!

List list = new LinkedList();
List spy = spy(list);

//Impossible: real method is called so spy.get(0) throws IndexOutOfBoundsException (the list is yet empty)
when(spy.get(0)).thenReturn("foo");

//You have to use doReturn() for stubbing
doReturn("foo").when(spy).get(0);

那么,when thenReturn何时无效{?1}}?

same question here

0 个答案:

没有答案