它们似乎都在做同样的事情--为什么你要优先使用其中一个而不是另一个?
org.mockito.Mockito.stub()
org.mockito.Mockito.mock()
发布于 2011-03-10 22:37:27
您可以使用模拟对象来验证您是否以预期的方式调用了它。在Mockito中,模拟对象自动是存根,并且验证是显式发生的。
来自莫基托的"Why do we need another mocking framework?"
Separation of stubbing and verification. Should let me code in line with intuition:
stub before execution, selectively verify interactions afterwards. I don’t
want any verification-related code before execution.
您可以在调用之前将调用的行为存根。例如(从Mockito主页):
when( mockedList.get(0)).thenReturn( "first" );
您可以在模拟对象被调用后验证它们之间的交互。例如:
verify( mockedList ).add("one");
https://stackoverflow.com/questions/5261194
复制相似问题