Can I delay a stubbed method response with Mockito?

后端 未结 4 1549
执笔经年
执笔经年 2020-12-07 17:21

I\'m writing unit tests now. I need to simulate long-run method with Mockito to test my implementation\'s timeout handling. Is it possible with Mockito?

Something li

4条回答
  •  心在旅途
    2020-12-07 17:53

    From mockito 2.8.44, org.mockito.internal.stubbing.answers.AnswersWithDelay is available for this purpose. Here's a sample usage

     doAnswer( new AnswersWithDelay( 1000,  new Returns("some-return-value")) ).when(myMock).myMockMethod();
    

提交回复
热议问题