久久久久久久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 的情況下模擬靜態(tài)方法

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

          <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 的情況下模擬靜態(tài)方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  在 JUnit 中進(jìn)行測試時,有什么方法可以模擬靜態(tài) util 方法嗎?

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

                  我知道 Powermock 可以模擬靜態(tài)調(diào)用,但我不想使用 Powermock.

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

                  還有其他選擇嗎?

                  推薦答案

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

                  (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) 在被測類中,將靜態(tài)直接調(diào)用替換為對封裝靜態(tài)調(diào)用本身的包級方法的調(diào)用:

                  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) 在測試和模擬封裝的包級方法時監(jiān)視被測類:

                  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();
                      }
                  }
                  

                  這是我寫的一篇關(guān)于間諜的文章,其中包括類似的案例,如果您需要更多見解: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

                  這篇關(guān)于如何在沒有 powermock 的情況下模擬靜態(tài)方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?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'>

                          • 主站蜘蛛池模板: 免费一级做a爰片久久毛片潮喷 | 色婷婷精品久久二区二区蜜臂av | 国产在线观看 | 久久久久国产精品一区二区 | 麻豆久久久久久 | 欧美精品在线一区二区三区 | 日本不卡在线视频 | 精品成人一区二区 | 精品日韩欧美一区二区 | 国产精品久久久久久久久久久新郎 | 韩日在线视频 | 中文字幕亚洲视频 | 亚洲成人毛片 | 精品国产网 | 激情毛片 | 日韩无| 高清久久久 | 久久久久久久久久久国产 | 成人黄视频在线观看 | 在线看亚洲 | av网址在线播放 | 爱高潮www亚洲精品 中文字幕免费视频 | 精品91av| 午夜视频在线免费观看 | 国产一区二区视频在线观看 | 欧美久| 日韩一区二区三区在线 | jizz18国产 | 国产在线精品一区二区三区 | 亚洲视频区 | 免费av毛片| 国产精品久久久久一区二区三区 | www.亚洲一区二区三区 | 91色啪| 久久久久久国产精品 | 国产精品av久久久久久毛片 | 97精品国产 | 国产免费福利在线 | 福利视频亚洲 | 国产一级片 | 三a毛片|