我試圖模擬一個方法的返回值,但是我得到了NotAMockException
。InjectMocks對象上的org.mockito.exceptions.misusing.NotAMockException
@InjectMocks
private MyService myService;
@Mock
private OtherServiceUsedInMyServiceAsAutowired otherServiceUsedInMyServiceAsAutowired;
裏面MyService
我有一個名爲myMethod()
方法,我想回到虛擬對象時,此方法被調用。
doReturn(someDummyObject).when(myService).myMethod(any(), any(), any());
並在那一點上,我得到的錯誤。我究竟做錯了什麼?完整的錯誤:
org.mockito.exceptions.misusing.NotAMockException:
Argument passed to when() is not a mock!
Example of correct stubbing:
doThrow(new RuntimeException()).when(mock).someMethod();
是實際創建一個模擬的@InjectMocks註釋嗎? –