mock如何为空 | 您所在的位置:网站首页 › mock注解报错 › mock如何为空 |
I try to run this test: @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); ... } but I get NullPointerException for: Mockito.when(routingClientMock. what am i missing? 解决方案 When you want to use the @Mock annotation you should use the MockitoJUnitRunner @RunWith(MockitoJUnitRunner.class) public class MockitoTest { @Mock private IRoutingObjHttpClient routingClientMock; @Test public void testSendRoutingRequest() throws Exception { // ... } } |
CopyRight 2018-2019 实验室设备网 版权所有 |