久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    <small id='404Ly'></small><noframes id='404Ly'>

      <bdo id='404Ly'></bdo><ul id='404Ly'></ul>

    <legend id='404Ly'><style id='404Ly'><dir id='404Ly'><q id='404Ly'></q></dir></style></legend>

        <tfoot id='404Ly'></tfoot>

        Mockito 如何僅模擬超類方法的調用

        Mockito How to mock only the call of a method of the superclass(Mockito 如何僅模擬超類方法的調用)

        <tfoot id='ksYBT'></tfoot>

        • <bdo id='ksYBT'></bdo><ul id='ksYBT'></ul>
                  <tbody id='ksYBT'></tbody>

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

                  <legend id='ksYBT'><style id='ksYBT'><dir id='ksYBT'><q id='ksYBT'></q></dir></style></legend>
                  <i id='ksYBT'><tr id='ksYBT'><dt id='ksYBT'><q id='ksYBT'><span id='ksYBT'><b id='ksYBT'><form id='ksYBT'><ins id='ksYBT'></ins><ul id='ksYBT'></ul><sub id='ksYBT'></sub></form><legend id='ksYBT'></legend><bdo id='ksYBT'><pre id='ksYBT'><center id='ksYBT'></center></pre></bdo></b><th id='ksYBT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ksYBT'><tfoot id='ksYBT'></tfoot><dl id='ksYBT'><fieldset id='ksYBT'></fieldset></dl></div>

                  本文介紹了Mockito 如何僅模擬超類方法的調用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我在一些測試中使用了 Mockito.

                  I'm using Mockito in some tests.

                  我有以下課程:

                  class BaseService {  
                      public void save() {...}  
                  }
                  
                  public Childservice extends BaseService {  
                      public void save(){  
                          //some code  
                          super.save();
                      }  
                  }   
                  

                  我只想模擬 ChildService 的第二次調用 (super.save).第一次調用必須調用真正的方法.有沒有辦法做到這一點?

                  I want to mock only the second call (super.save) of ChildService. The first call must call the real method. Is there a way to do that?

                  推薦答案

                  不,Mockito 不支持這個.

                  No, Mockito does not support this.

                  這可能不是您要尋找的答案,但您看到的是未應用設計原則的癥狀:

                  This might not be the answer you're looking for, but what you're seeing is a symptom of not applying the design principle:

                  優先組合優于繼承

                  如果您提取策略而不是擴展超類,問題就消失了.

                  If you extract a strategy instead of extending a super class the problem is gone.

                  如果你不被允許更改代碼,但無論如何你必須測試它,并且以這種尷尬的方式,仍然有希望.使用一些 AOP 工具(例如 AspectJ),您可以將代碼編織到超類方法中并完全避免其執行(糟糕).如果您使用代理,這不起作用,您必須使用字節碼修改(加載時編織或編譯時編織).也有一些模擬框架支持這種類型的技巧,例如 PowerMock 和 PowerMockito.

                  If however you are not allowed to change the code, but you must test it anyway, and in this awkward way, there is still hope. With some AOP tools (for example AspectJ) you can weave code into the super class method and avoid its execution entirely (yuck). This doesn't work if you're using proxies, you have to use bytecode modification (either load time weaving or compile time weaving). There are be mocking frameworks that support this type of trick as well, like PowerMock and PowerMockito.

                  我建議您進行重構,但如果這不是一個選項,您可以享受一些嚴肅的黑客樂趣.

                  I suggest you go for the refactoring, but if that is not an option you're in for some serious hacking fun.

                  這篇關于Mockito 如何僅模擬超類方法的調用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)

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

                    <tfoot id='G6x8d'></tfoot>
                      <tbody id='G6x8d'></tbody>

                      <bdo id='G6x8d'></bdo><ul id='G6x8d'></ul>
                      <legend id='G6x8d'><style id='G6x8d'><dir id='G6x8d'><q id='G6x8d'></q></dir></style></legend>

                          • <i id='G6x8d'><tr id='G6x8d'><dt id='G6x8d'><q id='G6x8d'><span id='G6x8d'><b id='G6x8d'><form id='G6x8d'><ins id='G6x8d'></ins><ul id='G6x8d'></ul><sub id='G6x8d'></sub></form><legend id='G6x8d'></legend><bdo id='G6x8d'><pre id='G6x8d'><center id='G6x8d'></center></pre></bdo></b><th id='G6x8d'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='G6x8d'><tfoot id='G6x8d'></tfoot><dl id='G6x8d'><fieldset id='G6x8d'></fieldset></dl></div>
                            主站蜘蛛池模板: 久久福利 | 国产在线一区二 | 亚洲国产高清高潮精品美女 | 成年人在线播放 | 99热这里有精品 | 亚州精品天堂中文字幕 | 一级片毛片 | 99热这里有精品 | 亚洲久草 | 国产欧美二区 | 午夜一级做a爰片久久毛片 精品综合 | 日本超碰 | 亚洲日本欧美 | 亚洲乱码国产乱码精品精98午夜 | 自拍偷拍中文字幕 | 久久伊| 亚洲一区在线播放 | 色就是色欧美 | 亚洲美女天堂网 | 国产成人精品久久 | 国产精品亚洲一区二区三区在线观看 | 久久99国产精品 | 国产综合精品 | 色天天综合 | 中文字幕精品视频 | 精品国产三级 | 黄色片a级 | 四虎影院新网址 | 国产日产久久高清欧美一区 | 国产精品视频一区二区三区 | 伊人性伊人情综合网 | 视频一区二区在线观看 | 中国人pornoxxx麻豆 | 国产成人精品一区二区三区四区 | 日韩精品一区二区三区 | 久久亚洲精品国产精品紫薇 | h视频在线免费 | 日本手机看片 | 国产精品自产av一区二区三区 | 久久久免费在线观看 | 亚洲精品一区二区三区蜜桃久 |