// mock掉同一个类的方法
ResultSureServiceImpl spy = spy(testService);
spy.testMethod();
// mock 静态方法
MockedStatic<OkHttpUtils> mockedStatic = null;
try {
mockedStatic = Mockito.mockStatic(OkHttpUtils.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
mockedStatic.when(() -> OkHttpUtils.post(any(), any(), any())).thenReturn(result);
// 执行完之后再用verify()
Mockito.verify(routeMapper, times(1)).selectByPrimaryKey(anyLong());
mock test
最新推荐文章于 2024-06-14 11:36:53 发布