在SpringBootTest中,如果要Mock一个Bean的无返回值的方法,则不能使用when(obj).thenReturn()
。
正确的做法是Mockito.doNothing().when(riskRoutingService).submit(Mockito.any());
在 @SpyBean
的注解对象上做Mock,也需要先do
,再when
。而 @MockBean
注解的对象则不用。
在SpringBootTest中,如果要Mock一个Bean的无返回值的方法,则不能使用when(obj).thenReturn()
。
正确的做法是Mockito.doNothing().when(riskRoutingService).submit(Mockito.any());
在 @SpyBean
的注解对象上做Mock,也需要先do
,再when
。而 @MockBean
注解的对象则不用。
本文标题:Spring Boot Test Mockito Mock Vo
本文链接:https://www.haomeiwen.com/subject/urijlktx.html
网友评论