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

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

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

    1. <i id='tjhHZ'><tr id='tjhHZ'><dt id='tjhHZ'><q id='tjhHZ'><span id='tjhHZ'><b id='tjhHZ'><form id='tjhHZ'><ins id='tjhHZ'></ins><ul id='tjhHZ'></ul><sub id='tjhHZ'></sub></form><legend id='tjhHZ'></legend><bdo id='tjhHZ'><pre id='tjhHZ'><center id='tjhHZ'></center></pre></bdo></b><th id='tjhHZ'></th></span></q></dt></tr></i><div class="0muiuee" id='tjhHZ'><tfoot id='tjhHZ'></tfoot><dl id='tjhHZ'><fieldset id='tjhHZ'></fieldset></dl></div>
      1. 使用 PowerMockito.whenNew() 不會被嘲笑,而是調用原

        Using PowerMockito.whenNew() is not getting mocked and original method is called(使用 PowerMockito.whenNew() 不會被嘲笑,而是調用原始方法)

        <small id='1NiOn'></small><noframes id='1NiOn'>

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

                  <bdo id='1NiOn'></bdo><ul id='1NiOn'></ul>
                    <tbody id='1NiOn'></tbody>

                • <legend id='1NiOn'><style id='1NiOn'><dir id='1NiOn'><q id='1NiOn'></q></dir></style></legend>
                  本文介紹了使用 PowerMockito.whenNew() 不會被嘲笑,而是調用原始方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個類似下面的代碼:

                  I have a code somewhat like this below:

                  Class A {
                    public boolean myMethod(someargs) {
                      MyQueryClass query = new MyQueryClass();
                      Long id = query.getNextId();
                      // some more code
                    }
                  }
                  Class MyQueryClass     {
                    ....
                    public Long getNextId() {
                      //lot of DB code, execute some DB query
                      return id;
                    }
                  }
                  

                  現在我正在為 A.myMethod(someargs) 編寫測試.我想跳過真正的方法 query.getNextId() 而是返回一個存根值.基本上,我想模擬 MyQueryClass.

                  Now I'am writing a test for A.myMethod(someargs). I want to skip the real method query.getNextId() and instead return a stub value. Basically, I want to mock MyQueryClass.

                  所以在我的測試用例中,我使用了:

                  So in my test case, I have used:

                  MyQueryClass query = PowerMockito.mock(MyQueryClass.class);
                  PowerMockito.whenNew(MyQueryClass.class).withNoArguments().thenReturn(query);
                  when(query.getNextId()).thenReturn(1000000L);
                  
                  boolean b = A.getInstance().myMethod(args);
                  
                  //asserts
                  

                  我在測試類的開頭使用了 @RunWith(PowerMockRunner.class)@PrepareForTest({MyQueryClass.class}).

                  I used @RunWith(PowerMockRunner.class) and @PrepareForTest({MyQueryClass.class}) in the beginning of my test class.

                  但是我調試測試的時候,還是調用了MyQueryClass類的真實方法getNextId().

                  But when I debug the test, it is still calling the real method getNextId() of the MyQueryClass class.

                  我在這里缺少什么?任何人都可以提供幫助,因為我是 Mockito 和 PowerMockito 的新手.

                  What am I missing here? Can anyone help as I am new to Mockito and PowerMockito.

                  推薦答案

                  需要將調用構造函數的類放到@PrepareForTest注解中,而不是正在構造的類 - 請參閱 模擬新對象的構造.

                  You need to put the class where the constructor is called into the @PrepareForTest annotation instead of the class which is being constructed - see Mock construction of new objects.

                  在你的情況下:

                  ? @PrepareForTest(MyQueryClass.class)

                  ? @PrepareForTest(A.class)

                  更籠統的:

                  ? @PrepareForTest(NewInstanceClass.class)

                  ? @PrepareForTest(ClassThatCreatesTheNewInstance.class)

                  這篇關于使用 PowerMockito.whenNew() 不會被嘲笑,而是調用原始方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)
                  <tfoot id='Kwey9'></tfoot>
                      <tbody id='Kwey9'></tbody>

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

                      • <bdo id='Kwey9'></bdo><ul id='Kwey9'></ul>
                        <legend id='Kwey9'><style id='Kwey9'><dir id='Kwey9'><q id='Kwey9'></q></dir></style></legend>
                        <i id='Kwey9'><tr id='Kwey9'><dt id='Kwey9'><q id='Kwey9'><span id='Kwey9'><b id='Kwey9'><form id='Kwey9'><ins id='Kwey9'></ins><ul id='Kwey9'></ul><sub id='Kwey9'></sub></form><legend id='Kwey9'></legend><bdo id='Kwey9'><pre id='Kwey9'><center id='Kwey9'></center></pre></bdo></b><th id='Kwey9'></th></span></q></dt></tr></i><div class="csys002" id='Kwey9'><tfoot id='Kwey9'></tfoot><dl id='Kwey9'><fieldset id='Kwey9'></fieldset></dl></div>

                            主站蜘蛛池模板: 西点培训学校_法式西点培训班_西点师培训_西点蛋糕培训-广州烘趣西点烘焙培训学院 | 长沙广告公司|长沙广告制作设计|长沙led灯箱招牌制作找望城湖南锦蓝广告装饰工程有限公司 | 郑州宣传片拍摄-TVC广告片拍摄-微电影短视频制作-河南优柿文化传媒有限公司 | 冷藏车厂家|冷藏车价格|小型冷藏车|散装饲料车厂家|程力专用汽车股份有限公司销售十二分公司 | 成都中天自动化控制技术有限公司 | 电气控制系统集成商-PLC控制柜变频控制柜-非标自动化定制-电气控制柜成套-NIDEC CT变频器-威肯自动化控制 | 光纤测温-荧光光纤测温系统-福州华光天锐光电科技有限公司 | 插针变压器-家用电器变压器-工业空调变压器-CD型电抗器-余姚市中驰电器有限公司 | YJLV22铝芯铠装电缆-MYPTJ矿用高压橡套电缆-天津市电缆总厂 | 筒瓦厂家-仿古瓦-寺庙-古建琉璃瓦-宜兴市古典园林建筑陶瓷厂有限公司 | 不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰]-不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰] | 高压微雾加湿器_工业加湿器_温室喷雾-昌润空气净化设备 | 水篦子|雨篦子|镀锌格栅雨水篦子|不锈钢排水篦子|地下车库水箅子—安平县云航丝网制品厂 | 巨野月嫂-家政公司-巨野县红墙安康母婴护理中心 | 河南不锈钢水箱_地埋水箱_镀锌板水箱_消防水箱厂家-河南联固供水设备有限公司 | 二手光谱仪维修-德国OBLF光谱仪|进口斯派克光谱仪-热电ARL光谱仪-意大利GNR光谱仪-永晖检测 | 郑州水质检测中心_井水检测_河南废气检测_河南中环嘉创检测 | 电动球阀_不锈钢电动球阀_电动三通球阀_电动调节球阀_上海湖泉阀门有限公司 | 中细软知识产权_专业知识产权解决方案提供商 | 上海橡胶接头_弹簧减震器_金属软接头厂家-上海淞江集团 | 包装机_厂家_价格-山东包装机有限公司 | 合肥花魁情感婚姻咨询中心_挽回爱情_修复婚姻_恋爱指南 | 华禹护栏|锌钢护栏_阳台护栏_护栏厂家-华禹专注阳台护栏、楼梯栏杆、百叶窗、空调架、基坑护栏、道路护栏等锌钢护栏产品的生产销售。 | CTP磁天平|小电容测量仪|阴阳极极化_双液系沸点测定仪|dsj电渗实验装置-南京桑力电子设备厂 | 【甲方装饰】合肥工装公司-合肥装修设计公司,专业从事安徽办公室、店面、售楼部、餐饮店、厂房装修设计服务 | 步进电机_agv电机_伺服马达-伺服轮毂电机-和利时电机 | 飞利浦LED体育场灯具-吸顶式油站灯-飞利浦LED罩棚灯-佛山嘉耀照明有限公司 | 密封无忧网 _ 专业的密封产品行业信息网| 5nd音乐网|最新流行歌曲|MP3歌曲免费下载|好听的歌|音乐下载 免费听mp3音乐 | 淘趣英语网 - 在线英语学习,零基础英语学习网站 | 双杰天平-国产双杰电子天平-美国双杰-常熟双杰仪器 | 并离网逆变器_高频UPS电源定制_户用储能光伏逆变器厂家-深圳市索克新能源 | 工装定制/做厂家/公司_工装订做/制价格/费用-北京圣达信工装 | 数控走心机-双主轴走心机厂家-南京建克| 超声波焊接机,振动摩擦焊接机,激光塑料焊接机,超声波焊接模具工装-德召尼克(常州)焊接科技有限公司 | 南京试剂|化学试剂|分析试剂|实验试剂|cas号查询-专业60年试剂销售企业 | 蓝鹏测控平台 - 智慧车间系统 - 车间生产数据采集与分析系统 | 打包箱房_集成房屋-山东佳一集成房屋有限公司 | 凝胶成像仪,化学发光凝胶成像系统,凝胶成像分析系统-上海培清科技有限公司 | 东莞市海宝机械有限公司-不锈钢分选机-硅胶橡胶-生活垃圾-涡电流-静电-金属-矿石分选机 | 运动木地板厂家_体育木地板安装_篮球木地板选购_实木运动地板价格 |