【发布时间】:2019-04-30 09:50:18
【问题描述】:
我正在使用 Spring Boot 进行测试(我对 Spring Boot 非常陌生),我想在测试阶段模拟我的 Rest API 脚本,所以我使用 MockRestServiceServer 创建一个模拟服务器。
现在,每当我运行 server.verify() 时,我总是会收到此错误
java.lang.AssertionError: Further request(s) expected leaving 1 unsatisfied expectation(s).
这是我的主要调用方法
@Test
public void call() {
RestTemplate template = Mockito.mock(RestTemplate.class);
server = MockRestServiceServer.createServer(template);
DataParser parser = Mockito.mock(DataParser.class);
RTCValidate validate = Mockito.mock(RTCValidate.class);
NodeExe nodeExe = Mockito.mock(NodeExe.class);
RTCInterpreter interpreter = new RTCInterpreter(parser, validate, nodeExe);
Mockito.when(parser.parse(Mockito.anyString(), Mockito.anyString())).thenReturn("2012-02-08");
server.expect(requestTo("http://vpn.fakemood.com/certmgmt/L1ip?uuid={uuid}")).andRespond(withSuccess("123ABC456", MediaType.TEXT_PLAIN));
server.verify();
}
我不确定为什么会出现这个错误,实际的 API 可以正常工作,实际代码也是如此。 URL 也是正确的,但是哪个期望失败了??
为什么会出现此错误,它实际上是什么意思??
提前感谢您的帮助
【问题讨论】:
标签: spring-boot junit mockito