久久久久久久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'>

                          主站蜘蛛池模板: 91免费高清视频 | 中文字幕1区2区 | 99久久日韩精品免费热麻豆美女 | 欧美久久一级特黄毛片 | 黄色电影在线免费观看 | 欧美日韩国产在线观看 | 免费看一级毛片 | 国产免费xxx | 国产成人精品一区二区三区在线 | 亚欧午夜 | 久久精品一| 欧美精品久久久久久久久老牛影院 | 日本一区二区在线视频 | 国产精品乱码一区二区三区 | 欧美日本一区 | 激情国产视频 | 男人亚洲天堂 | 97国产在线视频 | 日韩在线一区二区三区 | 久久久久久高潮国产精品视 | 中文成人在线 | 国产精品久久久久久久久大全 | 中文字幕高清av | 国产精品国产精品国产专区不蜜 | 亚洲午夜av | 视频在线一区二区 | 成人 在线 | 精品国产乱码久久久久久图片 | 亚洲精品免费在线 | 国产综合久久 | 中国黄色在线视频 | 成人午夜网 | 国产伦精品一区二区三区高清 | 在线国产欧美 | 国产福利免费视频 | 欧美一区二区三区视频在线 | 国产精品久久久久久婷婷天堂 | 国产精品美女久久久久久久网站 | 一区二区三区四区在线视频 | 国产精品毛片av一区 | 91色在线视频 |