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

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

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

  1. <tfoot id='fKX69'></tfoot>

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

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

      使用 PowerMockito 1.6 驗證靜態方法調用

      Verify Static Method Call using PowerMockito 1.6(使用 PowerMockito 1.6 驗證靜態方法調用)
          <bdo id='qBxoe'></bdo><ul id='qBxoe'></ul>

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

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

              <i id='qBxoe'><tr id='qBxoe'><dt id='qBxoe'><q id='qBxoe'><span id='qBxoe'><b id='qBxoe'><form id='qBxoe'><ins id='qBxoe'></ins><ul id='qBxoe'></ul><sub id='qBxoe'></sub></form><legend id='qBxoe'></legend><bdo id='qBxoe'><pre id='qBxoe'><center id='qBxoe'></center></pre></bdo></b><th id='qBxoe'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qBxoe'><tfoot id='qBxoe'></tfoot><dl id='qBxoe'><fieldset id='qBxoe'></fieldset></dl></div>
              • 本文介紹了使用 PowerMockito 1.6 驗證靜態方法調用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在為類似于下面給出的示例的方法編寫 JUnit 測試用例:

                I am writing JUnit test case for methods similar to sample given below:

                Class SampleA{
                    public static void methodA(){
                        boolean isSuccessful = methodB();
                        if(isSuccessful){
                            SampleB.methodC();
                        }
                    }
                
                    public static boolean methodB(){
                        //some logic
                        return true;
                    }
                }
                
                Class SampleB{
                    public static void methodC(){
                        return;
                    }
                }
                

                我在我的測試類中編寫了以下測試用例:

                I wrote the following test case in my test class:

                @Test
                public void testMethodA_1(){
                    PowerMockito.mockStatic(SampleA.class,SampleB.class);
                
                    PowerMockito.when(SampleA.methodB()).thenReturn(true);
                    PowerMockito.doNothing().when(SampleB.class,"methodC");
                
                    PowerMockito.doCallRealMethod().when(SampleA.class,"methodA");
                    SampleA.methodA();
                }
                

                現在我想驗證是否調用了 Sample B 類的靜態方法 C().如何使用 PowerMockito 1.6 實現?我已經嘗試了很多東西,但它似乎對我來說并不奏效.任何幫助表示贊賞.

                Now I want to verify whether static methodC() of class Sample B is called or not. How can I achieve using PowerMockito 1.6? I have tried many things but it doesn't seems to be working out for me. Any help is appreciated.

                推薦答案

                就個人而言,我不得不說 PowerMock 等是解決問題的解決方案,如果你的代碼還不錯的話,你不應該有.在某些情況下,它是必需的,因為框架等使用靜態方法會導致代碼根本無法測試,但如果是關于您的代碼,您應該始終更喜歡重構而不是靜態模擬.

                Personally, I have to say that PowerMock, etc. is the solution to a problem that you shouldn't have if your code wasn't bad. In some cases, it is required because frameworks, etc. use static methods that lead to code that simply cannot be tested otherwise, but if it's about YOUR code, you should always prefer refactoring instead of static mocking.

                無論如何,在 PowerMockito 中進行驗證應該不會那么難......

                Anyway, verifing that in PowerMockito shouldn't be that hard...

                PowerMockito.verifyStatic( Mockito.times(1)); // Verify that the following mock method was called exactly 1 time
                SampleB.methodC();
                

                (當然,要使其工作,您必須將 SampleB 添加到 @PrepareForTest 注釋并為其調用 mockStatic.)

                (Of course, for this to work you must add SampleB to the @PrepareForTest annotation and call mockStatic for it.)

                這篇關于使用 PowerMockito 1.6 驗證靜態方法調用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                  <tbody id='PUtlo'></tbody>

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

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

                • <tfoot id='PUtlo'></tfoot>

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

                          主站蜘蛛池模板: www亚洲精品 | 国产精品视频一 | 国产精品久久久久久久 | 老司机精品福利视频 | 国产亚洲一区二区三区 | 日本中文字幕视频 | 一级毛片观看 | 狠狠色狠狠色综合日日92 | 久久91精品久久久久久9鸭 | 国产精品久久国产精品 | 性一交一乱一透一a级 | 精品一区二区三区在线视频 | 亚洲国产精品久久久 | 一级黄片一级毛片 | 欧美日韩国产高清视频 | 国产91视频一区二区 | 成人午夜精品 | 高清黄色网址 | 日韩精品一区二区三区 | www国产成人免费观看视频 | 激情一区二区三区 | 免费污视频| 久久精品a| 91精品国产综合久久久密闭 | 国产精品福利久久久 | 中文字幕影院 | 一区二区三区欧美在线 | 午夜精品久久久久久久久久久久 | 超碰地址| 国产成人精品一区二区三区网站观看 | 综合在线视频 | 欧美高清dvd | 成人 在线| 久久精品av麻豆的观看方式 | 精品一区二区三区四区 | 午夜影院在线 | 福利社午夜影院 | a免费在线 | 久久美女网 | 99久久精品免费视频 | 午夜精品久久久久久久久久久久 |