@mock 注解后,模拟实例为 null |
您所在的位置:网站首页 › @mock注解 › @mock 注解后,模拟实例为 null |
@mock 注解后,模拟实例为 null
我尝试运行此测试: @Mock IRoutingObjHttpClient routingClientMock; @Mock IRoutingResponseRepository routingResponseRepositoryMock; @Test public void testSendRoutingRequest() throws Exception { CompleteRoutingResponse completeRoutingResponse = new CompleteRoutingResponse(); completeRoutingResponse.regression_latencyMillis = 500L; Mockito.when(routingClientMock.sendRoutingRequest(any(RoutingRequest.class))).thenReturn(completeRoutingResponse); RoutingObjHttpClientWithReRun routingObjHttpClientWithReRun = new RoutingObjHttpClientWithReRun (routingClientMock, routingResponseRepositoryMock); ... }但是我得到了 nullpoInterException: Mockito.when(routingClientMock.我想念什么? java 推荐答案当您要使用 @mock注解时,应该使用 MockitoJunitRunner @RunWith(MockitoJUnitRunner.class) public class MockitoTest { @Mock private IRoutingObjHttpClient routingClientMock; @Test public void testSendRoutingRequest() throws Exception { // ... } }另请参见本教程。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |