• <legend id='KyAvD'><style id='KyAvD'><dir id='KyAvD'><q id='KyAvD'></q></dir></style></legend>

        <bdo id='KyAvD'></bdo><ul id='KyAvD'></ul>

        <tfoot id='KyAvD'></tfoot>

        <i id='KyAvD'><tr id='KyAvD'><dt id='KyAvD'><q id='KyAvD'><span id='KyAvD'><b id='KyAvD'><form id='KyAvD'><ins id='KyAvD'></ins><ul id='KyAvD'></ul><sub id='KyAvD'></sub></form><legend id='KyAvD'></legend><bdo id='KyAvD'><pre id='KyAvD'><center id='KyAvD'></center></pre></bdo></b><th id='KyAvD'></th></span></q></dt></tr></i><div id='KyAvD'><tfoot id='KyAvD'></tfoot><dl id='KyAvD'><fieldset id='KyAvD'></fieldset></dl></div>

        <small id='KyAvD'></small><noframes id='KyAvD'>

        当我运行 mockito 测试时发生 WrongTypeOfReturnValue 异

        时间:2023-09-25

          <legend id='RJ4QQ'><style id='RJ4QQ'><dir id='RJ4QQ'><q id='RJ4QQ'></q></dir></style></legend>
            <tfoot id='RJ4QQ'></tfoot>

              <tbody id='RJ4QQ'></tbody>

              <small id='RJ4QQ'></small><noframes id='RJ4QQ'>

                <i id='RJ4QQ'><tr id='RJ4QQ'><dt id='RJ4QQ'><q id='RJ4QQ'><span id='RJ4QQ'><b id='RJ4QQ'><form id='RJ4QQ'><ins id='RJ4QQ'></ins><ul id='RJ4QQ'></ul><sub id='RJ4QQ'></sub></form><legend id='RJ4QQ'></legend><bdo id='RJ4QQ'><pre id='RJ4QQ'><center id='RJ4QQ'></center></pre></bdo></b><th id='RJ4QQ'></th></span></q></dt></tr></i><div id='RJ4QQ'><tfoot id='RJ4QQ'></tfoot><dl id='RJ4QQ'><fieldset id='RJ4QQ'></fieldset></dl></div>
                • <bdo id='RJ4QQ'></bdo><ul id='RJ4QQ'></ul>
                  本文介绍了当我运行 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.

                  As you can see, I am calling when on updateItemAttributes (which does return a boolean) not on updateItemAttributesByJuId.

                  1. 为什么 Mockito 试图从 updateItemAttributesByJuId 返回一个 boolean?
                  2. 如何改正?

                  推荐答案

                  根据https:///groups.google.com/forum/?fromgroups#!topic/mockito/9WUvkhZUy90,你应该改写你的

                  when(bar.getFoo()).thenReturn(fooBar)
                  

                  doReturn(fooBar).when(bar).getFoo()
                  

                  这篇关于当我运行 mockito 测试时发生 WrongTypeOfReturnValue 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  • <legend id='g1Kaj'><style id='g1Kaj'><dir id='g1Kaj'><q id='g1Kaj'></q></dir></style></legend>
                    • <bdo id='g1Kaj'></bdo><ul id='g1Kaj'></ul>
                      <i id='g1Kaj'><tr id='g1Kaj'><dt id='g1Kaj'><q id='g1Kaj'><span id='g1Kaj'><b id='g1Kaj'><form id='g1Kaj'><ins id='g1Kaj'></ins><ul id='g1Kaj'></ul><sub id='g1Kaj'></sub></form><legend id='g1Kaj'></legend><bdo id='g1Kaj'><pre id='g1Kaj'><center id='g1Kaj'></center></pre></bdo></b><th id='g1Kaj'></th></span></q></dt></tr></i><div id='g1Kaj'><tfoot id='g1Kaj'></tfoot><dl id='g1Kaj'><fieldset id='g1Kaj'></fieldset></dl></div>
                        <tbody id='g1Kaj'></tbody>
                    • <small id='g1Kaj'></small><noframes id='g1Kaj'>

                          <tfoot id='g1Kaj'></tfoot>