When to use Mockito.verify()?

后端 未结 6 1813
清酒与你
清酒与你 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:22

    As some people said

    1. Sometimes you don't have a direct output on which you can assert
    2. Sometimes you just need to confirm that your tested method is sending the correct indirect outputs to its collaborators (which you are mocking).

    Regarding your concern about breaking your tests when refactoring, that is somewhat expected when using mocks/stubs/spies. I mean that by definition and not regarding a specific implementation such as Mockito. But you could think in this way - if you need to do a refactoring that would create major changes on the way your method works, it is a good idea to do it on a TDD approach, meaning you can change your test first to define the new behavior (that will fail the test), and then do the changes and get the test passed again.

提交回复
热议问题