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

  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="ugcioik" 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="yiyeio0" 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="0co22y2" id='wrrSz'><tfoot id='wrrSz'></tfoot><dl id='wrrSz'><fieldset id='wrrSz'></fieldset></dl></div>
                          <tfoot id='wrrSz'></tfoot>
                          主站蜘蛛池模板: 接地电阻测试仪[厂家直销]_电缆故障测试仪[精准定位]_耐压测试仪-武汉南电至诚电力设备 | 细沙回收机-尾矿干排脱水筛设备-泥石分离机-建筑垃圾分拣机厂家-青州冠诚重工机械有限公司 | UV-1800紫外光度计-紫外可见光度计厂家-翱艺仪器(上海)有限公司 | 电销卡_北京电销卡_包月电话卡-豪付网络 | 南京泽朗生物科技有限公司-液体饮料代加工_果汁饮料代加工_固体饮料代加工 | 餐饮加盟网_特色餐饮连锁加盟店-餐饮加盟官网 | 河南凯邦机械制造有限公司 | 云南丰泰挖掘机修理厂-挖掘机维修,翻新,再制造的大型企业-云南丰泰工程机械维修有限公司 | 药品冷藏箱厂家_低温冰箱_洁净工作台-济南欧莱博电子商务有限公司官网 | 超声波电磁流量计-液位计-孔板流量计-料位计-江苏信仪自动化仪表有限公司 | MTK核心板|MTK开发板|MTK模块|4G核心板|4G模块|5G核心板|5G模块|安卓核心板|安卓模块|高通核心板-深圳市新移科技有限公司 | 折弯机-刨槽机-数控折弯机-数控刨槽机-数控折弯机厂家-深圳豐科机械有限公司 | 手术室净化厂家-成都做医院净化工程的公司-四川华锐-15年特殊科室建设经验 | 净化车间_洁净厂房_净化公司_净化厂房_无尘室工程_洁净工程装修|改造|施工-深圳净化公司 | 赛尔特智能移动阳光房-阳光房厂家-赛尔特建筑科技(广东)有限公司 | 全钢实验台,实验室工作台厂家-无锡市辰之航装饰材料有限公司 | 亚洲工业智能制造领域专业门户网站 - 亚洲自动化与机器人网 | 聚合氯化铝-碱式氯化铝-聚合硫酸铁-聚氯化铝铁生产厂家多少钱一吨-聚丙烯酰胺价格_河南浩博净水材料有限公司 | 雨水收集系统厂家-雨水收集利用-模块雨水收集池-徐州博智环保科技有限公司 | Magnescale探规,Magnescale磁栅尺,Magnescale传感器,Magnescale测厚仪,Mitutoyo光栅尺,笔式位移传感器-苏州连达精密量仪有限公司 | 仓储笼_金属箱租赁_循环包装_铁网箱_蝴蝶笼租赁_酷龙仓储笼租赁 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | VOC检测仪-甲醛检测仪-气体报警器-气体检测仪厂家-深恒安科技有限公司 | 四川职高信息网-初高中、大专、职业技术学校招生信息网 | 安徽控制器-合肥船用空调控制器-合肥家电控制器-合肥迅驰电子厂 安徽净化板_合肥岩棉板厂家_玻镁板厂家_安徽科艺美洁净科技有限公司 | 高空重型升降平台_高空液压举升平台_高空作业平台_移动式升降机-河南华鹰机械设备有限公司 | 上海办公室装修_上海店铺装修公司_厂房装潢设计_办公室装修 | 动库网动库商城-体育用品专卖店:羽毛球,乒乓球拍,网球,户外装备,运动鞋,运动包,运动服饰专卖店-正品运动品网上商城动库商城网 - 动库商城 | 影合社-影视人的内容合作平台| 一体化预制泵站-一体化提升泵站-一体化泵站厂家-山东康威环保 | 高清视频编码器,4K音视频编解码器,直播编码器,流媒体服务器,深圳海威视讯技术有限公司 | 飞利浦LED体育场灯具-吸顶式油站灯-飞利浦LED罩棚灯-佛山嘉耀照明有限公司 | 液晶拼接屏厂家_拼接屏品牌_拼接屏价格_监控大屏—北京维康 | 聚天冬氨酸,亚氨基二琥珀酸四钠,PASP,IDS - 远联化工 | 浙江宝泉阀门有限公司| 电动手术床,医用护理床,led手术无影灯-曲阜明辉医疗设备有限公司 | 温湿度记录纸_圆盘_横河记录纸|霍尼韦尔记录仪-广州汤米斯机电设备有限公司 | 一体化污水处理设备_生活污水处理设备_全自动加药装置厂家-明基环保 | 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 工业冷却塔维修厂家_方形不锈钢工业凉水塔维修改造方案-广东康明节能空调有限公司 | ISO9001认证咨询_iso9001企业认证代理机构_14001|18001|16949|50430认证-艾世欧认证网 | 北京浩云律师事务所-法律顾问_企业法务_律师顾问_公司顾问 |