How to mock void methods with Mockito

前端 未结 9 2209
情话喂你
情话喂你 2020-11-22 12:21

How to mock methods with void return type?

I implemented an observer pattern but I can\'t mock it with Mockito because I don\'t know how.

And I tried to fin

9条回答
  •  萌比男神i
    2020-11-22 13:05

    The solution of so-called problem is to use a spy Mockito.spy(...) instead of a mock Mockito.mock(..).

    Spy enables us to partial mocking. Mockito is good at this matter. Because you have class which is not complete, in this way you mock some required place in this class.

提交回复
热议问题