什么时候使用 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章