mock如何为空 您所在的位置:网站首页 mock注解报错 mock如何为空

mock如何为空

2024-07-16 15:14| 来源: 网络整理| 查看: 265

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 实验室设备网 版权所有