使用JMockit测试RESTful API,RestTemplate,错误调用缺失

时间:2016-07-15 11:55:37

标签: rest testing jmockit

我正在学习使用JMockit来测试我的Restful API。缺少调用错误正在滥用我。 Restful API:
@RestController 公共类AgentInfoRest {

$scope.options = {
            scales: {
                xAxes: [{
                    gridLines: {
                        display: false
                    }
        }],
                yAxes: [{
                    gridLines: {
                        display: false
                    }
        }]
            }
        };

}
测试类:
公共类AgentInfoRestTest {

@Autowired
AgentInfoRepository agentInfoRepository;

private Logger logger = LoggerFactory.getLogger(AgentInfoRest.class);

@RequestMapping("/allagentInfo")
RestResponse getAllAgentInfo()
{
    RestResponse restResponse = new RestResponse();
    logger.info("getAllAgentInfo has no request parameter");
    Collection<AgentInfo> result = agentInfoRepository.getAllAgents();
    if(result.isEmpty())
    {
        restResponse.setRetCode(-1);
        restResponse.setRetMsg("Request success,no such record in db");
    }
    restResponse.setResult(result);
    return restResponse;
}

}
错误:
mockit.internal.MissingInvocation:缺少调用: com.egoo.dao.repository.freelink.AgentInfoRepository#getAllAgents()    在mock实例上:com.egoo.dao.repository.freelink.$Impl_AgentInfoRepository@50a7bc6e

String host = "http://127.0.0.1:8080";

@Test
public void getAllAgentInfoTest(@Mocked final AgentInfoRepository agentInfoRepository) {

    RestTemplate restTemplate = new RestTemplate();
    RestResponse restResponse = new RestResponse();
    AgentInfoRest agentInfoRest = new AgentInfoRest();
    new StrictExpectations() {
        {
            agentInfoRepository.getAllAgents(); result = null; times = 1;
        }
    };
    String url = "/allagentInfo";
    ResponseEntity<RestResponse> result = restTemplate.getForEntity(host + url, RestResponse.class);
    new FullVerifications() {
        {
        }
    };
}

引起:缺少调用     在com.egoo.dao.rest.freelink.AgentInfoRestTest $ 1.(AgentInfoRestTest.java:33)     at com.egoo.dao.rest.freelink.AgentInfoRestTest.getAllAgentInfoTest(AgentInfoRestTest.java:31)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at java.lang.reflect.Method.invoke(Method.java:498)     ......还有7个

0 个答案:

没有答案