Java Mockito 错误不适用于参数(无效)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29537574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mockito Error Is Not Applicable for the Arguments (void)
提问by Reginald
Mockito throws error "The method when(T) in the type Stubber is not applicable for the arguments (void)"
for a class I'm mocking, can't figure out why.
Mockito"The method when(T) in the type Stubber is not applicable for the arguments (void)"
为我正在嘲笑的课程抛出错误,不知道为什么。
the code in question is:
有问题的代码是:
Mockito.when(mockObject.myMethod(Mockito.any(MyExecutionContext.class))).thenReturn(value);
I'm aware similar questions have been asked but if somebody could explain a solution for this or point me in the right direction I would greatly appreciate it
我知道有人问过类似的问题,但如果有人可以为此解释解决方案或为我指明正确的方向,我将不胜感激
采纳答案by Reginald
Solution:
解决方案:
Mockito.doReturn(value)
.when(mockObject)
.myMethod(Mockito.any(MyExecutionContext??.class))