久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <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="qwawimqqmiuu" id='kwi0n'><tfoot id='kwi0n'></tfoot><dl id='kwi0n'><fieldset id='kwi0n'></fieldset></dl></div>

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

        何時使用 Mockito.verify()?

        When to use Mockito.verify()?(何時使用 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="qwawimqqmiuu" id='rTWV1'><tfoot id='rTWV1'></tfoot><dl id='rTWV1'><fieldset id='rTWV1'></fieldset></dl></div>

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

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

                  問題描述

                  我為 3 個目的編寫 jUnit 測試用例:

                  I write jUnit test cases for 3 purposes:

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

                  我不明白為什么或何時應該使用 Mockito.verify().當我看到 verify() 被調用時,它告訴我我的 jUnit 正在意識到該實現.(因此更改我的實現會破壞我的 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() 的指南應該是什么?

                  jUnits 了解或緊密耦合到被測類的實現是否從根本上正確?

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

                  推薦答案

                  如果類 A 的契約包括它調用 C 類型對象的方法 B 的事實,那么您應該通過制作 C 類型的模擬來測試這一點,并驗證方法 B 是否已被調用.

                  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 的契約有足夠的細節來討論類型 C(可能是接口或類).所以是的,我們談論的規范級別不僅僅是系統要求",而是在某種程度上描述了實現.

                  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.

                  這對于單元測試是正常的.當您進行單元測試時,您希望確保每個單元都在做正確的事情",這通常包括它與其他單元的交互.這里的單元"可能是指類或應用程序的更大子集.

                  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.

                  更新:

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

                  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.

                  根據我的經驗,如果我改變一個類的實現,我經常不得不改變它的單元測試的實現來匹配.不過,通常情況下,我不必更改類的單元測試清單;當然,除非更改的原因是存在我之前未能測試的條件.

                  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.

                  這就是單元測試的意義所在.不受這種對協作者類使用方式的依賴影響的測試實際上是子系統測試或集成測試.當然,這些也經常使用 JUnit 編寫,并且經常涉及到 mocking 的使用.在我看來,JUnit"是一個糟糕的名字,因為它可以讓我們進行所有不同類型的測試.

                  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.

                  這篇關于何時使用 Mockito.verify()?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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?)

                    <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="qwawimqqmiuu" 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>

                            主站蜘蛛池模板: 国产视频中文字幕 | 国产va| 国产免费福利小视频 | 国产精品久久久久久亚洲调教 | 福利视频一区二区 | 日日摸夜夜爽人人添av | 91麻豆精品一区二区三区 | 欧美日韩久久精品 | 少妇精品亚洲一区二区成人 | 日韩在线一区二区三区 | 日本午夜网站 | 天堂影院av | 成人亚洲精品久久久久软件 | 日韩精品1区2区3区 成人黄页在线观看 | 超碰伊人久久 | 日韩精品一区二区三区 | 欧美高清视频 | 午夜a区 | 国产精品96久久久久久 | 久久99蜜桃综合影院免费观看 | 亚洲欧美激情国产综合久久久 | 亚洲精品九九 | 亚洲精品aⅴ | 中文字幕动漫成人 | 亚洲网站在线播放 | 91免费在线看 | 国产精品不卡视频 | 欧美一级欧美三级在线观看 | av中文字幕在线 | 国产成人免费网站 | 成年免费大片黄在线观看一级 | 国产精品国产亚洲精品看不卡15 | 中文字幕 国产 | 欧美亚洲另类丝袜综合网动图 | 第一av | 高清一区二区三区 | 日韩中文在线视频 | 日韩在线不卡 | 欧美精品一区二区三区在线播放 | 神马久久春色视频 | 在线亚洲一区二区 |