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

  • <legend id='kwi0n'><style id='kwi0n'><dir id='kwi0n'><q id='kwi0n'></q></dir></style></legend>

    <tfoot id='kwi0n'></tfoot>
      <bdo id='kwi0n'></bdo><ul id='kwi0n'></ul>

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

    2. <small id='kwi0n'></small><noframes id='kwi0n'>

        何時(shí)使用 Mockito.verify()?

        When to use Mockito.verify()?(何時(shí)使用 Mockito.verify()?)
        1. <tfoot id='rTWV1'></tfoot>

              <bdo id='rTWV1'></bdo><ul id='rTWV1'></ul>
            • <legend id='rTWV1'><style id='rTWV1'><dir id='rTWV1'><q id='rTWV1'></q></dir></style></legend>
            • <small id='rTWV1'></small><noframes id='rTWV1'>

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

                    <tbody id='rTWV1'></tbody>

                  本文介紹了何時(shí)使用 Mockito.verify()?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我為 3 個(gè)目的編寫 jUnit 測試用例:

                  I write jUnit test cases for 3 purposes:

                  1. 為了確保我的代碼在所有(或大部分)輸入組合/值下滿足所有必需的功能.
                  2. 為了確保我可以更改實(shí)現(xiàn),并依靠 JUnit 測試用例告訴我我的所有功能仍然得到滿足.
                  3. 作為我的代碼處理的所有用例的文檔,并充當(dāng)重構(gòu)規(guī)范 - 如果代碼需要重寫.(重構(gòu)代碼,如果我的 jUnit 測試失敗 - 你可能錯(cuò)過了一些用例).

                  我不明白為什么或何時(shí)應(yīng)該使用 Mockito.verify().當(dāng)我看到 verify() 被調(diào)用時(shí),它告訴我我的 jUnit 正在意識(shí)到該實(shí)現(xiàn).(因此更改我的實(shí)現(xiàn)會(huì)破壞我的 jUnit,即使我的功能不受影響).

                  I do not understand why or when Mockito.verify() should be used. When I see verify() being called, it is telling me that my jUnit is becoming aware of the implementation. (Thus changing my implementation would break my jUnits, even though my functionality was unaffected).

                  我正在尋找:

                  1. 正確使用 Mockito.verify() 的指南應(yīng)該是什么?

                  jUnits 了解或緊密耦合到被測類的實(shí)現(xiàn)是否從根本上正確?

                  Is it fundamentally correct for jUnits to be aware of, or tightly coupled to, the implementation of the class under test?

                  推薦答案

                  如果類 A 的契約包括它調(diào)用 C 類型對象的方法 B 的事實(shí),那么您應(yīng)該通過制作 C 類型的模擬來測試這一點(diǎn),并驗(yàn)證方法 B 是否已被調(diào)用.

                  If the contract of class A includes the fact that it calls method B of an object of type C, then you should test this by making a mock of type C, and verifying that method B has been called.

                  這意味著類 A 的契約有足夠的細(xì)節(jié)來討論類型 C(可能是接口或類).所以是的,我們談?wù)摰囊?guī)范級別不僅僅是系統(tǒng)要求",而是在某種程度上描述了實(shí)現(xiàn).

                  This implies that the contract of class A has sufficient detail that it talks about type C (which might be an interface or a class). So yes, we're talking about a level of specification that goes beyond just "system requirements", and goes some way to describing implementation.

                  這對于單元測試是正常的.當(dāng)您進(jìn)行單元測試時(shí),您希望確保每個(gè)單元都在做正確的事情",這通常包括它與其他單元的交互.這里的單元"可能是指類或應(yīng)用程序的更大子集.

                  This is normal for unit tests. When you are unit testing, you want to ensure that each unit is doing the "right thing", and that will usually include its interactions with other units. "Units" here might mean classes, or larger subsets of your application.

                  更新:

                  我覺得這不僅適用于驗(yàn)證,也適用于存根.一旦您存根協(xié)作者類的方法,您的單元測試就在某種意義上變得依賴于實(shí)現(xiàn).這有點(diǎn)像單元測試的性質(zhì).由于 Mockito 與驗(yàn)證一樣重要,因此您使用 Mockito 的事實(shí)意味著您將遇到這種依賴關(guān)系.

                  I feel that this doesn't apply just to verification, but to stubbing as well. As soon as you stub a method of a collaborator class, your unit test has become, in some sense, dependent on implementation. It's kind of in the nature of unit tests to be so. Since Mockito is as much about stubbing as it is about verification, the fact that you're using Mockito at all implies that you're going to run across this kind of dependency.

                  根據(jù)我的經(jīng)驗(yàn),如果我改變一個(gè)類的實(shí)現(xiàn),我經(jīng)常不得不改變它的單元測試的實(shí)現(xiàn)來匹配.不過,通常情況下,我不必更改類的單元測試清單;當(dāng)然,除非更改的原因是存在我之前未能測試的條件.

                  In my experience, if I change the implementation of a class, I often have to change the implementation of its unit tests to match. Typically, though, I won't have to change the inventory of what unit tests there are for the class; unless of course, the reason for the change was the existence of a condition that I failed to test earlier.

                  這就是單元測試的意義所在.不受這種對協(xié)作者類使用方式的依賴影響的測試實(shí)際上是子系統(tǒng)測試或集成測試.當(dāng)然,這些也經(jīng)常使用 JUnit 編寫,并且經(jīng)常涉及到 mocking 的使用.在我看來,JUnit"是一個(gè)糟糕的名字,因?yàn)樗梢宰屛覀冞M(jìn)行所有不同類型的測試.

                  So this is what unit tests are about. A test that doesn't suffer from this kind of dependency on the way collaborator classes are used is really a sub-system test or an integration test. Of course, these are frequently written with JUnit too, and frequently involve the use of mocking. In my opinion, "JUnit" is a terrible name, for a product that lets us produce all different types of test.

                  這篇關(guān)于何時(shí)使用 Mockito.verify()?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)

                    <small id='2t54i'></small><noframes id='2t54i'>

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

                          <tbody id='2t54i'></tbody>
                          <tfoot id='2t54i'></tfoot>
                          <legend id='2t54i'><style id='2t54i'><dir id='2t54i'><q id='2t54i'></q></dir></style></legend>
                            <bdo id='2t54i'></bdo><ul id='2t54i'></ul>

                            主站蜘蛛池模板: 数显恒温油浴-电砂浴-高温油浴振荡器-常州迈科诺仪器有限公司 | 房在线-免费房产管理系统软件-二手房中介房屋房源管理系统软件 | 网络推广公司_网络营销方案策划_企业网络推广外包平台-上海澜推网络 | 线粒体膜电位荧光探针-细胞膜-标记二抗-上海复申生物科技有限公司 | 航空连接器,航空插头,航空插座,航空接插件,航插_深圳鸿万科 | 一体化隔油提升设备-餐饮油水分离器-餐厨垃圾处理设备-隔油池-盐城金球环保产业发展有限公司 | 带式压滤机_污泥压滤机_污泥脱水机_带式过滤机_带式压滤机厂家-河南恒磊环保设备有限公司 | 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | 防爆鼓风机-全风-宏丰鼓风机-上海梁瑾机电设备有限公司 | 重庆磨床过滤机,重庆纸带过滤机,机床伸缩钣金,重庆机床钣金护罩-重庆达鸿兴精密机械制造有限公司 | 法兰螺母 - 不锈钢螺母制造厂家 - 万千紧固件--螺母街 | 中宏网-今日新闻-财经新闻| 隆众资讯-首页_大宗商品资讯_价格走势_市场行情 | 对辊破碎机_四辊破碎机_双齿辊破碎机_华盛铭重工 | 石家庄装修设计_室内家装设计_别墅装饰装修公司-石家庄金舍装饰官网 | sfp光模块,高速万兆光模块工厂-性价比更高的光纤模块制造商-武汉恒泰通 | 不锈钢复合板厂家_钛钢复合板批发_铜铝复合板供应-威海泓方金属复合材料股份有限公司 | EPDM密封胶条-EPDM密封垫片-EPDM生产厂家 | U拓留学雅思一站式服务中心_留学申请_雅思托福培训 | 磁粉制动器|张力控制器|气胀轴|伺服纠偏控制器整套厂家--台灵机电官网 | 云南丰泰挖掘机修理厂-挖掘机维修,翻新,再制造的大型企业-云南丰泰工程机械维修有限公司 | LED太阳能中国结|发光红灯笼|灯杆造型灯|节日灯|太阳能灯笼|LED路灯杆装饰造型灯-北京中海轩光电 | 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 - 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 | 危废处理系统,水泥厂DCS集散控制系统,石灰窑设备自动化控制系统-淄博正展工控设备 | 应急灯_消防应急灯_应急照明灯_应急灯厂家-大成智慧官网 | 沈阳液压泵_沈阳液压阀_沈阳液压站-沈阳海德太科液压设备有限公司 | 聚合氯化铝-碱式氯化铝-聚合硫酸铁-聚氯化铝铁生产厂家多少钱一吨-聚丙烯酰胺价格_河南浩博净水材料有限公司 | 螺纹三通快插接头-弯通快插接头-宁波舜驰气动科技有限公司 | 脱硝喷枪-氨水喷枪-尿素喷枪-河北思凯淋环保科技有限公司 | 干式变压器厂_干式变压器厂家_scb11/scb13/scb10/scb14/scb18干式变压器生产厂家-山东科锐变压器有限公司 | 西宁装修_西宁装修公司-西宁业之峰装饰-青海业之峰墅级装饰设计公司【官网】 | 减速机_上海宜嘉减速机| 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 - 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 | 间甲酚,间甲酚厂家-山东祥东新材料 | Dataforth隔离信号调理模块-信号放大模块-加速度振动传感器-北京康泰电子有限公司 | 棕刚玉-白刚玉厂家价格_巩义市东翔净水材料厂 | 舞台木地板厂家_体育运动木地板_室内篮球馆木地板_实木运动地板厂家_欧氏篮球地板推荐 | 北京网站建设首页,做网站选【优站网】,专注北京网站建设,北京网站推广,天津网站建设,天津网站推广,小程序,手机APP的开发。 | 游泳池设备安装工程_恒温泳池设备_儿童游泳池设备厂家_游泳池水处理设备-东莞市君达泳池设备有限公司 | 济南拼接屏_山东液晶拼接屏_济南LED显示屏—维康国际官网 | 清洁设备_洗地机/扫地机厂家_全自动洗地机_橙犀清洁设备官网 |