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

  1. <tfoot id='l2jSA'></tfoot>
  2. <legend id='l2jSA'><style id='l2jSA'><dir id='l2jSA'><q id='l2jSA'></q></dir></style></legend>

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

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

        <bdo id='l2jSA'></bdo><ul id='l2jSA'></ul>

      PowerMock,模擬一個靜態方法,然后在所有其他靜

      PowerMock, mock a static method, THEN call real methods on all other statics(PowerMock,模擬一個靜態方法,然后在所有其他靜態上調用真實方法)

            <tbody id='RtUah'></tbody>

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

            <tfoot id='RtUah'></tfoot>
            <legend id='RtUah'><style id='RtUah'><dir id='RtUah'><q id='RtUah'></q></dir></style></legend>
              <bdo id='RtUah'></bdo><ul id='RtUah'></ul>
              • <i id='RtUah'><tr id='RtUah'><dt id='RtUah'><q id='RtUah'><span id='RtUah'><b id='RtUah'><form id='RtUah'><ins id='RtUah'></ins><ul id='RtUah'></ul><sub id='RtUah'></sub></form><legend id='RtUah'></legend><bdo id='RtUah'><pre id='RtUah'><center id='RtUah'></center></pre></bdo></b><th id='RtUah'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RtUah'><tfoot id='RtUah'></tfoot><dl id='RtUah'><fieldset id='RtUah'></fieldset></dl></div>
                本文介紹了PowerMock,模擬一個靜態方法,然后在所有其他靜態上調用真實方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在設置模擬類的靜態方法.我必須在 @Before 注釋的 JUnit 設置方法中執行此操作.

                I'm setting up mocking a class' static methods. I have to do this in a @Before-annotated JUnit setup method.

                我的目標是設置類來調用真正的方法,除了那些我明確模擬的方法.

                My goal is to setup the class to call real methods, except for those methods I explicitly mock.

                基本上:

                @Before
                public void setupStaticUtil() {
                  PowerMockito.mockStatic(StaticUtilClass.class);
                
                  // mock out certain methods...
                  when(StaticUtilClass.someStaticMethod(anyString())).thenReturn(5); 
                
                  // Now have all OTHER methods call the real implementation???  How do I do this?
                }
                

                我遇到的問題是在 StaticUtilClass 方法 public static int someStaticMethod(String s) 不幸地拋出了一個 RuntimeException 如果提供 null 值.

                The problem I'm running into is that within StaticUtilClass the method public static int someStaticMethod(String s) unfortunately throws a RuntimeException if supplied with a null value.

                所以我不能簡單地將調用真實方法作為默認答案的明顯路線如下:

                So I can't simply go the obvious route of calling real methods as the default answer as below:

                @Before
                public void setupStaticUtil() {
                  PowerMockito.mockStatic(StaticUtilClass.class, CALLS_REAL_METHODS); // Default to calling real static methods
                
                  // The below call to someStaticMethod() will throw a RuntimeException, as the arg is null!
                  // Even though I don't actually want to call the method, I just want to setup a mock result
                  when(StaticUtilClass.someStaticMethod(antString())).thenReturn(5); 
                }
                

                我需要設置默認答案以在所有其他靜態方法上調用真實方法之后我模擬了我感興趣的方法的結果.

                I need to set the default Answer to call real methods on all other static methods after I mock the results from the method I'm interested in mocking.

                這可能嗎?

                推薦答案

                你在找什么叫做partial mocking.

                在 PowerMock 中你可以使用 mockStaticPartial 方法.

                In PowerMock you can use mockStaticPartial method.

                在 PowerMockito 中,您可以使用存根,它只會存根定義的方法,而其他保持不變:

                In PowerMockito you can use stubbing, which will stub only the method defined and leave other unchanged:

                PowerMockito.stub(PowerMockito.method(StaticUtilClass.class, "someStaticMethod")).toReturn(5);
                

                也別忘了

                @PrepareForTest(StaticUtilClass.class)
                

                這篇關于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?)
                  <bdo id='wrrSz'></bdo><ul id='wrrSz'></ul>
                  <legend id='wrrSz'><style id='wrrSz'><dir id='wrrSz'><q id='wrrSz'></q></dir></style></legend>
                    <tbody id='wrrSz'></tbody>
                  1. <small id='wrrSz'></small><noframes id='wrrSz'>

                      1. <i id='wrrSz'><tr id='wrrSz'><dt id='wrrSz'><q id='wrrSz'><span id='wrrSz'><b id='wrrSz'><form id='wrrSz'><ins id='wrrSz'></ins><ul id='wrrSz'></ul><sub id='wrrSz'></sub></form><legend id='wrrSz'></legend><bdo id='wrrSz'><pre id='wrrSz'><center id='wrrSz'></center></pre></bdo></b><th id='wrrSz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='wrrSz'><tfoot id='wrrSz'></tfoot><dl id='wrrSz'><fieldset id='wrrSz'></fieldset></dl></div>
                          <tfoot id='wrrSz'></tfoot>
                          主站蜘蛛池模板: 亚洲一二三在线观看 | 日韩精品在线网站 | 黄色男女网站 | 黄视频免费 | 在线看亚洲 | 91精品国产综合久久精品 | 99小视频 | 欧美精品久久久久 | 成人午夜看片 | 精品久久久久国产免费第一页 | 日韩欧美在线观看一区 | 久久精品一级 | 性做久久久久久免费观看欧美 | 手机看片在线播放 | 国产精品高潮呻吟久久久久 | 亚洲免费观看视频 | 精品欧美一区二区中文字幕视频 | 久久一 | 国产一区二区三区色淫影院 | 九九热精品在线视频 | 日本一区视频在线观看 | 精品一区二区三区免费视频 | 中文字幕一区二区三 | 日韩福利在线观看 | 免费国产视频 | 国产欧美在线 | 午夜激情视频 | 午夜电影网站 | 天天看天天操 | 一级黄色在线 | 精品九九九 | 午夜精品久久久久久久久久久久久 | 国产精品久久久久影院色老大 | 精品欧美视频 | 国产激情91久久精品导航 | 亚洲国产成人精品女人久久久 | 免费成人av | 国产伦一区二区三区 | 久久精品国产v日韩v亚洲 | 超碰免费在线 | 天天色天天射天天干 |