pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="rjpnzfl" id='fKX69'><tfoot id='fKX69'></tfoot><dl id='fKX69'><fieldset id='fKX69'></fieldset></dl></div>

      使用 PowerMockito 1.6 驗證靜態(tài)方法調用

      Verify Static Method Call using PowerMockito 1.6(使用 PowerMockito 1.6 驗證靜態(tài)方法調用)
          <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="bjr7xl7" id='qBxoe'><tfoot id='qBxoe'></tfoot><dl id='qBxoe'><fieldset id='qBxoe'></fieldset></dl></div>
              • 本文介紹了使用 PowerMockito 1.6 驗證靜態(tài)方法調用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在為類似于下面給出的示例的方法編寫 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();
                }
                

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

                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 等是解決問題的解決方案,如果你的代碼還不錯的話,你不應該有.在某些情況下,它是必需的,因為框架等使用靜態(tài)方法會導致代碼根本無法測試,但如果是關于您的代碼,您應該始終更喜歡重構而不是靜態(tài)模擬.

                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 驗證靜態(tài)方法調用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(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(如何在給定范圍內創(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?)
                  <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="77jzj7b" 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'>

                          主站蜘蛛池模板: 全自动过滤器_反冲洗过滤器_自清洗过滤器_量子除垢环_量子环除垢_量子除垢 - 安士睿(北京)过滤设备有限公司 | 氧化铁红厂家-淄博宗昂化工 | 哈尔滨治「失眠/抑郁/焦虑症/精神心理」专科医院排行榜-京科脑康免费咨询 一对一诊疗 | 南京泽朗生物科技有限公司-液体饮料代加工_果汁饮料代加工_固体饮料代加工 | 不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰]-不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰] | 芜湖厨房设备_芜湖商用厨具_芜湖厨具设备-芜湖鑫环厨具有限公司 控显科技 - 工控一体机、工业显示器、工业平板电脑源头厂家 | 烟气在线监测系统_烟气在线监测仪_扬尘检测仪_空气质量监测站「山东风途物联网」 | 在线浊度仪_悬浮物污泥浓度计_超声波泥位计_污泥界面仪_泥水界面仪-无锡蓝拓仪表科技有限公司 | 智能电表|预付费ic卡水电表|nb智能无线远传载波电表-福建百悦信息科技有限公司 | 青州搬家公司电话_青州搬家公司哪家好「鸿喜」青州搬家 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 真石漆,山东真石漆,真石漆厂家,真石漆价格-山东新佳涂料有限公司 | 鄂泉泵业官网|(杭州、上海、全国畅销)大流量防汛排涝泵-LW立式排污泵 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 | WF2户外三防照明配电箱-BXD8050防爆防腐配电箱-浙江沃川防爆电气有限公司 | 上海皓越真空设备有限公司官网-真空炉-真空热压烧结炉-sps放电等离子烧结炉 | 板材品牌-中国胶合板行业十大品牌-环保板材-上海声达板材 | 无刷电机_直流无刷电机_行星减速机-佛山市藤尺机电设备有限公司 无菌检查集菌仪,微生物限度仪器-苏州长留仪器百科 | 利浦顿蒸汽发生器厂家-电蒸汽发生器/燃气蒸汽发生器_湖北利浦顿热能科技有限公司官网 | 长沙发电机-湖南发电机-柴油发电机供应厂家-长沙明邦智能科技 | 济南轻型钢结构/济南铁艺护栏/济南铁艺大门-济南燕翔铁艺制品有限公司 | 对照品_中药对照品_标准品_对照药材_「格利普」高纯中药标准品厂家-成都格利普生物科技有限公司 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 诺冠气动元件,诺冠电磁阀,海隆防爆阀,norgren气缸-山东锦隆自动化科技有限公司 | 成都珞石机械 - 模温机、油温机、油加热器生产厂家 | 跨境物流_美国卡派_中大件运输_尾程派送_海外仓一件代发 - 广州环至美供应链平台 | 危废处理系统,水泥厂DCS集散控制系统,石灰窑设备自动化控制系统-淄博正展工控设备 | 铝镁锰板_铝镁锰合金板_铝镁锰板厂家_铝镁锰金属屋面板_安徽建科 | 电子书导航网_电子书之家_电子书大全_最新电子书分享发布平台 | CE认证_FCC认证_CCC认证_MFI认证_UN38.3认证-微测检测 CNAS实验室 | 深圳市源和塑胶电子有限公司-首页 | ZHZ8耐压测试仪-上海胜绪电气有限公司 | 市政路灯_厂家-淄博信达电力科技有限公司 | 全自动面膜机_面膜折叠机价格_面膜灌装机定制_高速折棉机厂家-深圳市益豪科技有限公司 | 防爆电机-高压防爆电机-ybx4电动机厂家-河南省南洋防爆电机有限公司 | 砍排机-锯骨机-冻肉切丁机-熟肉切片机-预制菜生产线一站式服务厂商 - 广州市祥九瑞盈机械设备有限公司 | 南京泽朗生物科技有限公司-液体饮料代加工_果汁饮料代加工_固体饮料代加工 | 锡膏喷印机-全自动涂覆机厂家-全自动点胶机-视觉点胶机-深圳市博明智控科技有限公司 | 圆盘鞋底注塑机_连帮鞋底成型注塑机-温州天钢机械有限公司 | Q361F全焊接球阀,200X减压稳压阀,ZJHP气动单座调节阀-上海戎钛 | 扬州汇丰仪表有限公司 | 不锈钢拉手厂家|浴室门拉手厂家|江门市蓬江区金志翔五金制品有限公司 |