久久久久久久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)方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

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

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

                  我知道 Powermock 可以模擬靜態(tài)調用,但我不想使用 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) 在被測類中,將靜態(tài)直接調用替換為對封裝靜態(tài)調用本身的包級方法的調用:

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

                  這是我寫的一篇關于間諜的文章,其中包括類似的案例,如果您需要更多見解: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 的情況下模擬靜態(tài)方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個隨機打亂數(shù)字的 int 數(shù)組)
                  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'>

                          • 主站蜘蛛池模板: 国产精品福利网站 | 欧美男人天堂 | 免费国产视频 | 日本精品一区二区三区视频 | 亚洲国产欧美精品 | 亚州一区二区三区 | 欧美激情综合 | 色性av| 国产精品免费一区二区三区四区 | 亚洲欧美日韩电影 | 亚洲视频a| 久久看精品| 在线视频中文字幕 | 欧美一级免费片 | 不卡一区 | 日韩精品免费在线观看 | 久久久久无码国产精品一区 | 欧美性视频在线播放 | 成人免费淫片aa视频免费 | 日韩高清中文字幕 | 偷拍自拍网址 | 久操伊人| 久久综合99 | 亚洲综合一区二区三区 | 国产精品五月天 | 黄色一级大片视频 | 亚洲国产一区二区三区在线观看 | 中文成人在线 | www.成人在线视频 | 免费特级黄毛片 | 久久久久久久久久久福利观看 | 国产午夜精品一区二区三区 | 亚洲va欧美va天堂v国产综合 | 日本小视频网站 | 国产精品亚洲欧美日韩一区在线 | 国产成人精品一区二区三区视频 | 欧美激情免费在线 | 亚洲精品日韩在线观看 | 欧美视频区| 视频在线一区二区 | 欧美一级特黄aaa大片在线观看 |