use*_*342 7 java unit-testing mockito
在以下示例中:
   Execution execution = mock(Execution.class);
   when(execution.getLastQty()).thenReturn(1000.0);
   when(execution.getLastPrice()).thenReturn(75.0);
   order.onFillReceived(execution);
   assertEquals(0, order.getLeavesQty(), 0);
执行还有许多其他不应该被调用的方法.在此测试中只应使用已经模拟的两种方法,并且应该调用它们.如果调用任何其他方法,则测试应该失败.
如果调用任何其他方法,如何告诉Mockito失败?
该文档明确涵盖了这一点.您想verifyNoMoreInteractions在致电verify(根据文档)或之后致电
verify(execution).getLastQty();
verify(execution).getLastPrice();
verifyNoMoreInteractions(execution);
或使用ignoreStubs:
verifyNoMoreInteractions(ignoreStubs(execution));
| 归档时间: | 
 | 
| 查看次数: | 4727 次 | 
| 最近记录: |