我不明白为什么 doNothing
对此不起作用?有什么想法吗?
@Captor
ArgumentCaptor<GenericClass<someOtherClass>> captor;
...
Mockito.doNothing().when(mockObject.methodToStub(captor.capture()));
错误是:
Exception: when(java.lang.Void) in Stubber cannot be applied to void
最佳答案
这个 stub 是错误的:
doNothing().when(mockObject.methodToStub(captor.capture())); // wrong
methodToStub(...)
如果使用此 API 样式,则必须在 when
之外(它应该只包含模拟):
doNothing().when(mockObject).methodToStub(captor.capture()); // correct
然而,尽管评论:
doNothing
是模拟的 void 方法的默认值。- 您可以使用
BDDMockito
别名,使您的代码成为真正的à la 行为驱动开发
关于java - Mockito 问题 - Stubber 中的 when(java.lang.Void) 无法应用于 void,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25249902/