久久久久久久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>
                            主站蜘蛛池模板: 中文字幕在线免费 | av一二三四 | 欧美日韩欧美 | 欧美国产日韩一区 | 97精品超碰一区二区三区 | 精品国产91乱码一区二区三区 | 亚洲欧美日本国产 | 亚洲激情在线视频 | 天堂一区二区三区 | 欧美成人自拍视频 | 神马久久香蕉 | 亚洲一区二区三区在线 | 精品三级在线观看 | 欧美成人精品一区二区三区 | 精品无码久久久久久国产 | 免费成人高清 | 国产精品毛片 | 一区二区在线不卡 | 91国内视频在线 | 日韩欧美在线一区 | 成年免费在线观看 | 91免费电影| 国产精品视频一二三 | 国产在线小视频 | 亚洲综合视频 | 91福利在线观看视频 | 中文在线视频 | 成人毛片一区二区三区 | 国产精品亚洲成在人线 | 狠狠干网站 | 欧美日韩成人在线 | 久久国产传媒 | 亚洲三区视频 | 国产在线一区二区三区 | 国产你懂的在线观看 | 99久久精品国产一区二区三区 | 最新黄色毛片 | 日韩高清中文字幕 | 亚洲精品乱码久久久久久按摩观 | 亚洲国产中文字幕 | 色视频网站 |