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

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

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

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

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

    1. 如何使用 PowerMockito 模擬私有靜態(tài)方法?

      How can I mock private static method with PowerMockito?(如何使用 PowerMockito 模擬私有靜態(tài)方法?)

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

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

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

          <tfoot id='EnFIk'></tfoot>
          • <bdo id='EnFIk'></bdo><ul id='EnFIk'></ul>
                  <tbody id='EnFIk'></tbody>

                本文介紹了如何使用 PowerMockito 模擬私有靜態(tài)方法?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在嘗試模擬私有靜態(tài)方法 anotherMethod().見下面的代碼

                I'm trying to mock private static method anotherMethod(). See code below

                public class Util {
                    public static String method(){
                        return anotherMethod();
                    }
                
                    private static String anotherMethod() {
                        throw new RuntimeException(); // logic was replaced with exception.
                    }
                }
                

                這是我的測試代碼

                @PrepareForTest(Util.class)
                public class UtilTest extends PowerMockTestCase {
                
                        @Test
                        public void should_prevent_invoking_of_private_method_but_return_result_of_it() throws Exception {
                
                            PowerMockito.mockStatic(Util.class);
                            PowerMockito.when(Util.class, "anotherMethod").thenReturn("abc");
                
                            String retrieved = Util.method();
                
                            assertNotNull(retrieved);
                            assertEquals(retrieved, "abc");
                        }    
                }
                

                但是我運(yùn)行的每一個圖塊都會出現(xiàn)這個異常

                But every tile I run it I get this exception

                java.lang.AssertionError: expected object to not be null
                

                我想我在嘲笑東西方面做錯了.有什么想法可以解決嗎?

                I suppose that I'm doing something wrong with mocking stuff. Any ideas how can I fix it?

                推薦答案

                為此,您可以使用 PowerMockito.spy(...)PowerMockito.doReturn(...).

                To to this, you can use PowerMockito.spy(...) and PowerMockito.doReturn(...).

                此外,您必須在測試類中指定 PowerMock 運(yùn)行器,并準(zhǔn)備測試類,如下所示:

                Moreover, you have to specify the PowerMock runner at your test class, and prepare the class for testing, as follows:

                @PrepareForTest(Util.class)
                @RunWith(PowerMockRunner.class)
                public class UtilTest {
                
                   @Test
                   public void testMethod() throws Exception {
                      PowerMockito.spy(Util.class);
                      PowerMockito.doReturn("abc").when(Util.class, "anotherMethod");
                
                      String retrieved = Util.method();
                
                      Assert.assertNotNull(retrieved);
                      Assert.assertEquals(retrieved, "abc");
                   }
                }
                

                希望對你有幫助.

                這篇關(guān)于如何使用 PowerMockito 模擬私有靜態(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?)

              • <tfoot id='vx2vA'></tfoot>
                    <tbody id='vx2vA'></tbody>

                      <legend id='vx2vA'><style id='vx2vA'><dir id='vx2vA'><q id='vx2vA'></q></dir></style></legend>
                      • <bdo id='vx2vA'></bdo><ul id='vx2vA'></ul>

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

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

                        • 主站蜘蛛池模板: 伊人精品在线 | 亚洲欧美日韩精品久久亚洲区 | 午夜精品久久久久久久久久久久久 | 国产精品国产成人国产三级 | 午夜av一区二区 | 91资源在线观看 | 久草免费福利 | 欧美激情视频一区二区三区在线播放 | 欧美日韩国产高清视频 | 一级做受毛片免费大片 | 在线一区视频 | 国产精品高潮呻吟久久 | 天天综合日日夜夜 | 夜久久| 午夜影院毛片 | 欧洲毛片| 玖玖视频 | 麻豆av在线免费观看 | 中文字幕在线观看 | 精品日韩欧美一区二区 | 麻豆精品国产免费 | 国产区免费视频 | 美美女高清毛片视频免费观看 | 99国产精品一区二区三区 | 人妖一区 | 精品国产乱码久久久久久a丨 | 欧美激情网站 | 国产精品美女久久久久久免费 | 亚洲精品久久久久中文字幕欢迎你 | 九色porny自拍视频 | 91免费在线 | 日韩在线精品 | 日韩精品在线视频免费观看 | 国产精品特级毛片一区二区三区 | 亚洲三级在线观看 | 久久久国产精品入口麻豆 | 日韩精品一区二区三区中文在线 | 亚洲欧美中文日韩在线v日本 | 国产福利91精品一区二区三区 | 人人人人干 | 亚洲精品一区二三区不卡 |