什麼時候使用 Mockito.verify()? - When to use Mockito.verify()?

問題:

I write jUnit test cases for 3 purposes:我爲 3 個目的編寫 jUnit 測試用例:

  1. To ensure that my code satisfies all of the required functionality, under all (or most of) the input combinations/values.爲了確保我的代碼滿足所有(或大部分)輸入組合/值下的所有必需功能。
  2. To ensure that I can change the implementation, and rely on JUnit test cases to tell me that all my functionality is still satisfied.確保我可以更改實現,並依靠 JUnit 測試用例告訴我我的所有功能仍然滿足。
  3. As a documentation of all the use cases my code handles, and act as a spec for refactoring - should the code ever need to be rewritten.作爲我的代碼處理的所有用例的文檔,並作爲重構的規範 - 如果代碼需要重寫。 (Refactor the code, and if my jUnit tests fail - you probably missed some use case). (重構代碼,如果我的 jUnit 測試失敗 - 您可能錯過了一些用例)。

I do not understand why or when Mockito.verify() should be used.我不明白爲什麼或何時應該使用Mockito.verify() When I see verify() being called, it is telling me that my jUnit is becoming aware of the implementation.當我看到調用verify() ,它告訴我我的 jUnit 正在意識到實現。 (Thus changing my implementation would break my jUnits, even though my functionality was unaffected). (因此更改我的實現會破壞我的 jUnit,即使我的功能不受影響)。

I'm looking for:我在找:

  1. What should be the guidelines for appropriate usage of Mockito.verify() ?適當使用Mockito.verify()的準則應該是什麼?

  2. Is it fundamentally correct for jUnits to be aware of, or tightly coupled to, the implementation of the class under test? jUnits 知道或緊密耦合到被測類的實現是否從根本上是正確的?


解決方案:

參考一: https://en.stackoom.com/question/qc3p
參考二: https://stackoom.com/question/qc3p
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章