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

后端 未结 5 1078
庸人自扰
庸人自扰 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条回答
  •  萌比男神i
    2020-12-12 16:43

    To add a bit to accepted answer ...

    If you get an UnfinishedStubbingException, be sure to set the method to be stubbed after the when closure, which is different than when you write Mockito.when

    Mockito.doNothing().when(mock).method()    //method is declared after 'when' closes
    
    Mockito.when(mock.method()).thenReturn(something)   //method is declared inside 'when'
    

提交回复
热议问题