我真的不在乎什么时候调用 mock - 几乎,我正在将一堆 mock 迁移到真实世界的代码中,因为集成测试中的 mock 有时非常愚蠢。
无论如何,在这里我有一个充满模拟设置的巨大类 - 但我真正想要的是在每个测试中找出使用了哪些模拟。
使用 mockito,我是否可以在实际执行特定“时间”时获取它,我不知道,“记录”或打印或其他东西?
最佳答案
从 Mockito 1.9.0 开始,您可以使用 verboseLogging设置。
例如,这个:
@Test
public void testLogging() {
final List<?> mockList = mock(List.class, withSettings().verboseLogging());
when(mockList.size()).thenReturn(6);
mockList.size();
}
产生:
###### Logging method invocation #1 on mock/spy ######## list.size(); invoked: -> atsoanswers.mockito.LogCalls.testLogging(LogCalls.java:35) has returned: "0" (java.lang.Integer)
###### Logging method invocation #2 on mock/spy ######## stubbed: -> atsoanswers.mockito.LogCalls.testLogging(LogCalls.java:35) list.size(); invoked: -> at soanswers.mockito.LogCalls.testLogging(LogCalls.java:37) has returned: "6" (java.lang.Integer)
关于java,mockito - 我如何找出调用了哪些模拟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14882203/