<bdo id='4GvkA'></bdo><ul id='4GvkA'></ul>
  • <legend id='4GvkA'><style id='4GvkA'><dir id='4GvkA'><q id='4GvkA'></q></dir></style></legend>

        <i id='4GvkA'><tr id='4GvkA'><dt id='4GvkA'><q id='4GvkA'><span id='4GvkA'><b id='4GvkA'><form id='4GvkA'><ins id='4GvkA'></ins><ul id='4GvkA'></ul><sub id='4GvkA'></sub></form><legend id='4GvkA'></legend><bdo id='4GvkA'><pre id='4GvkA'><center id='4GvkA'></center></pre></bdo></b><th id='4GvkA'></th></span></q></dt></tr></i><div id='4GvkA'><tfoot id='4GvkA'></tfoot><dl id='4GvkA'><fieldset id='4GvkA'></fieldset></dl></div>
      1. <small id='4GvkA'></small><noframes id='4GvkA'>

        <tfoot id='4GvkA'></tfoot>
      2. 使用 mockito 模拟构造函数

        时间:2023-09-25

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

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

                  <tbody id='AUNgP'></tbody>

                • 本文介绍了使用 mockito 模拟构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想将构造函数模拟为方法.

                  I want to mock a constructor into method.

                  public String generaID() {   
                      GeneraIDParaEntidadCliente aux = new GeneraIDParaEntidadCliente(nombre, registro);   
                      entidad.setID(aux.generaID);   
                  }
                  

                  在我的测试中,我想做这样的事情:

                  In my test I want do something like this :

                  when(new GeneraIDParaEntidadCliente(anyString(), any(Entidad.class)).thenReturn(generaIdMock)  
                  

                  但是给我这个error org.mockito.exceptions.misusing.InvalidUseOfMatchersException:

                  知道为什么吗?

                  推荐答案

                  可以使用 PowerMock 来模拟构造函数.

                  You can use PowerMock to mock constructors.

                  如果由于某种原因不能使用 PowerMock,最可行的解决方案是将工厂注入到包含此方法的任何类.然后,您将使用工厂创建您的 GeneraIDParaEntidadCliente 对象并模拟工厂.

                  If you can't use PowerMock for some reason, the most workable solution is to inject a factory to whatever class contains this method. You would then use the factory to create your GeneraIDParaEntidadCliente object and mock the factory.

                  这篇关于使用 mockito 模拟构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么我在使用 PowerMockRunner 运行时不能使用 @ 下一篇:PowerMockito:使用匹配器模拟静态方法时出现 Inval

                  相关文章

                  最新文章

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

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

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

                    • <bdo id='pKFrn'></bdo><ul id='pKFrn'></ul>