【发布时间】:2014-11-13 23:10:53
【问题描述】:
This code from the documentation 完全让我困惑:
List list = new LinkedList();
List spy = spy(list);
when(spy.size()).thenReturn(100); // <--- how does this spy know
// not to call the real method????
//using the spy calls *real* methods
spy.add("one");
spy.add("two");
我明白了,Mockito 很奇怪,几乎还没有在 Java 中使用。令人困惑的是spy.* 必须在知道它是否包含在when() 或其他东西中之前进行全面评估。第一个spy.* 方法到底怎么会不调用真实对象,而后面的方法会调用呢?
【问题讨论】:
-
之前已经回答过了。请看stackoverflow.com/questions/11620103/…
-
@nadirsaghar 我看不出你链接到的答案是如何回答这个问题的。
标签: java unit-testing mocking mockito spy