我有这样的when
通话:
@Mock
private MyEventFactory myEventFactory;
@Mock
private MyEvent myEvent;
when(myEventFactory.createMyEvent(anyObject(),anyObject(),anyObject(),anyObject(),anyObject(),anyObject(),anyObject(),anyObject(),anyObject(),anyObject(),anyObject())).thenReturn(myEvent);
但是我遇到例外
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Misplaced argument matcher detected here:
You cannot use argument matchers outside of verification or stubbing.
MyEventFactory是一个接口
这里可能是什么问题?
答案 0 :(得分:0)
您是否已初始化模拟?查看完整的代码会有所帮助,但我怀疑您需要调用类似的
MockitoAnnotations.initMocks(this);
在运行when
语句之前。本文显示了一个示例:https://howtodoinjava.com/mockito/mockito-mock-initmocks/