Lỗi chi tiết:khi tôi chạy thử nghiệm Mockito xảy ra WrongTypeOfReturnValue Exception
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.
mã của tôi:
@InjectMocks
protected ItemArrangeManager arrangeManagerSpy = spy(new ItemArrangeManagerImpl());
@Mock
protected JuItemWriteService juItemWriteService;
when(arrangeManagerSpy
.updateItemAttributes(mapCaptor.capture(), eq(juId), eq(itemTO.getSellerId())))
.thenReturn(false);
Như bạn thấy, tôi kêu gọi when
trên updateItemAttributes
(mà không trả về một boolean
) không trên updateItemAttributesByJuId
.
- Tại sao Mockito cố gắng trả lại
boolean
từupdateItemAttributesByJuId
? - Làm cách nào để sửa lỗi này?
Tks, tôi làm như thế này, sau đó nó hoạt động tốt –
@confusedwindbell Xem xét đánh dấu câu trả lời là được chấp nhận nếu nó giải quyết được vấn đề của bạn. –
Tôi đã có một lỗi tương tự và giải pháp này làm việc cho tôi. – YLombardi