When to use Mockito.verify()?

后端 未结 6 1821
清酒与你
清酒与你 2020-12-12 09:41

I write jUnit test cases for 3 purposes:

  1. To ensure that my code satisfies all of the required functionality, under all (or most of) the input combinations/valu
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-12 10:26

    I must say, that you are absolutely right from a classical approach's point of view:

    • If you first create (or change) business logic of your application and then cover it with (adopt) tests (Test-Last approach), then it will be very painful and dangerous to let tests know anything about how your software works, other than checking inputs and outputs.
    • If you are practicing a Test-Driven approach, then your tests are the first to be written, to be changed and to reflect the use cases of your software's functionality. The implementation depends on tests. That sometimes mean, that you want your software to be implemented in some particular way, e.g. rely on some other component's method or even call it a particular amount of times. That is where Mockito.verify() comes in handy!

    It is important to remember, that there are no universal tools. The type of software, it's size, company goals and market situation, team skills and many other things influence the decision on which approach to use at your particular case.

提交回复
热议问题