当我运行 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);

如您所见,我在 when updateItemAttributes (它确实返回 boolean )而不是在 updateItemAttributesByJuId

  1. 为什么 Mockito 试图从 — 返回 boolean updateItemAttributesByJuId
  2. 如何纠正?

原文由 confused windbell 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 4.5k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题