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

      <legend id='zHTtb'><style id='zHTtb'><dir id='zHTtb'><q id='zHTtb'></q></dir></style></legend>

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

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

      <tfoot id='zHTtb'></tfoot>
        <bdo id='zHTtb'></bdo><ul id='zHTtb'></ul>

        如何在沒有 powermock 的情況下模擬靜態方法

        How to mock static method without powermock(如何在沒有 powermock 的情況下模擬靜態方法)

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

            <tbody id='EzB43'></tbody>

        • <tfoot id='EzB43'></tfoot>
        • <legend id='EzB43'><style id='EzB43'><dir id='EzB43'><q id='EzB43'></q></dir></style></legend>

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

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

                  本文介紹了如何在沒有 powermock 的情況下模擬靜態方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在 JUnit 中進行測試時,有什么方法可以模擬靜態 util 方法嗎?

                  Is there any way we can mock the static util method while testing in JUnit?

                  我知道 Powermock 可以模擬靜態調用,但我不想使用 Powermock.

                  I know Powermock can mock static calls, but I don't want to use Powermock.

                  還有其他選擇嗎?

                  推薦答案

                  (不過我假設你可以使用 Mockito)我沒有想到任何專門的東西,但是當涉及到這樣的情況時,我傾向于使用以下策略:

                  (I assume you can use Mockito though) Nothing dedicated comes to my mind but I tend to use the following strategy when it comes to situations like that:

                  1) 在被測類中,將靜態直接調用替換為對封裝靜態調用本身的包級方法的調用:

                  1) In the class under test, replace the static direct call with a call to a package level method that wraps the static call itself:

                  public class ToBeTested{
                  
                      public void myMethodToTest(){
                           ...
                           String s = makeStaticWrappedCall();
                           ...
                      }
                  
                      String makeStaticWrappedCall(){
                          return Util.staticMethodCall();
                      }
                  }
                  

                  2) 在測試和模擬封裝的包級方法時監視被測類:

                  2) Spy the class under test while testing and mock the wrapped package level method:

                  public class ToBeTestedTest{
                  
                      @Spy
                      ToBeTested tbTestedSpy = new ToBeTested();
                  
                      @Before
                      public void init(){
                          MockitoAnnotations.initMocks(this);
                      }
                  
                      @Test
                      public void myMethodToTestTest() throws Exception{
                         // Arrange
                         doReturn("Expected String").when(tbTestedSpy).makeStaticWrappedCall();
                  
                         // Act
                         tbTestedSpy.myMethodToTest();
                      }
                  }
                  

                  這是我寫的一篇關于間諜的文章,其中包括類似的案例,如果您需要更多見解:sourceartists.com/mockito-spying

                  Here is an article I wrote on spying that includes similar case, if you need more insight: sourceartists.com/mockito-spying

                  這篇關于如何在沒有 powermock 的情況下模擬靜態方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)

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

                        <bdo id='D6QFe'></bdo><ul id='D6QFe'></ul>
                          <tbody id='D6QFe'></tbody>
                          <tfoot id='D6QFe'></tfoot>

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

                          • 主站蜘蛛池模板: 2021狠狠干| 国产精品美女久久久久久免费 | 免费高清成人 | 国产激情片在线观看 | 国产一区 | 韩国av网站在线观看 | 91视频久久| 国产精品电影在线观看 | 精品日韩一区二区 | 久久草视频 | 国产欧美精品一区二区三区 | 欧洲视频一区二区 | 在线视频久久 | 日韩一区二区三区四区五区六区 | 日日射夜夜骑 | 国产精品毛片一区二区在线看 | 亚洲精品久久视频 | 激情91| 久久国产精品一区二区 | 综合视频在线 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 午夜在线影院 | 我想看一级黄色毛片 | 精品三区 | 国产成人精品免费 | 一级a性色生活片久久毛片波多野 | 国产99久久久国产精品 | 综合色婷婷| 波多野结衣亚洲 | 中文字幕在线观看视频网站 | 精品国产高清一区二区三区 | 亚洲一区二区av | 成人av电影免费在线观看 | 国产一区二区三区视频在线观看 | 欧美久久一区 | 国产精品色 | 亚州av在线 | 免费毛片网站在线观看 | 精品国产精品国产偷麻豆 | 婷婷五月色综合香五月 | 夜夜骑综合 |