我尝试运行此测试:
@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.
我想念什么?
MockitoAnnotations.initMocks(this)
吗?(可能在@Before方法中)或者,您还有其他想要初始化模拟的@Rule吗?(这不是自动魔术)