Simulate first call fails, second call succeeds

前端 未结 5 1595
傲寒
傲寒 2021-01-30 15:24

I want to use Mockito to test the (simplified) code below. I don\'t know how to tell Mockito to fail the first time, then succeed the second time.

for(int i = 1;         


        
5条回答
  •  臣服心动
    2021-01-30 15:57

    Since the comment that relates to this is hard to read, I'll add a formatted answer.

    If you are trying to do this with a void function that just throws an exception, followed by a no behavior step, then you would do something like this:

    Mockito.doThrow(new Exception("MESSAGE"))
                .doNothing()
                .when(mockService).method(eq());
    

提交回复
热议问题