How to mock void methods with Mockito

前端 未结 9 2291
情话喂你
情话喂你 2020-11-22 12:21

How to mock methods with void return type?

I implemented an observer pattern but I can\'t mock it with Mockito because I don\'t know how.

And I tried to fin

9条回答
  •  天命终不由人
    2020-11-22 12:59

    I think I've found a simpler answer to that question, to call the real method for just one method (even if it has a void return) you can do this:

    Mockito.doCallRealMethod().when().();
    .();
    

    Or, you could call the real method for all methods of that class, doing this:

      = mock(.class, Mockito.CALLS_REAL_METHODS);
    
        

    提交回复
    热议问题