Usages of doThrow() doAnswer() doNothing() and doReturn() in mockito

后端 未结 5 1074
庸人自扰
庸人自扰 2020-12-12 16:01

I was learning mockito and I understood the basic usages of the above mentioned functions from the link.

But I would like to know whether it can be used for any othe

5条回答
  •  春和景丽
    2020-12-12 16:54

    It depends on the kind of test double you want to interact with:

    • If you don't use doNothing and you mock an object, the real method is not called
    • If you don't use doNothing and you spy an object, the real method is called

    In other words, with mocking the only useful interactions with a collaborator are the ones that you provide. By default functions will return null, void methods do nothing.

提交回复
热议问题