錯誤細節:當我運行的Mockito測試時WrongTypeOfReturnValue異常
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
Boolean cannot be returned by updateItemAttributesByJuId()
updateItemAttributesByJuId() should return ResultRich
This exception might occur in wrongly written multi-threaded tests.
Please refer to Mockito FAQ on limitations of concurrency testing.
我的代碼:
@InjectMocks
protected ItemArrangeManager arrangeManagerSpy = spy(new ItemArrangeManagerImpl());
@Mock
protected JuItemWriteService juItemWriteService;
when(arrangeManagerSpy
.updateItemAttributes(mapCaptor.capture(), eq(juId), eq(itemTO.getSellerId())))
.thenReturn(false);
正如你所看到的,我呼籲updateItemAttributes
when
(它返回一個boolean
)不在updateItemAttributesByJuId
。
- 爲什麼Mockito試圖從
updateItemAttributesByJuId
返回boolean
? - 這怎麼解決?
Tks,我喜歡這樣,然後它運作良好 –
@confusedwindbell考慮標記答案爲接受,如果它解決了你的問題。 –
我有類似的錯誤,這個解決方案適用於我。 – YLombardi