Throw a RuntimeException when invoking an unstubbed method

后端 未结 4 750
滥情空心
滥情空心 2020-12-09 02:44

I\'m using Mockito. I want to throw a RuntimeException when an unstubbed method is called.

Is there any way to do this?

4条回答
  •  萌比男神i
    2020-12-09 03:14

    You mock an entire class and the result is that all methods will return null.

    Then you can use doReturn(...) to change that behavior. Similarly, you can use doThrow(...) to make (as I recall only void) methods throw exceptions.

    Does that answer your question?

提交回复
热议问题