【发布时间】:2016-01-26 02:18:24
【问题描述】:
我正在尝试为我的 spring 集成流程编写集成测试。我想用 MockRestServiceServer 记录和匹配输出请求(使用 http:outbound-gateway)到 Rest 服务器。但是,当我调用 mockServer 的 verify 方法时,它并没有像预期的那样进行验证。
我正在按以下方式编写测试:
RestTemplate restTemplate = new RestTemplate();
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(requestTo("adfasfadf.com")).andExpect(method(HttpMethod.GET));
// Call spring integration flow here
mockServer.verify();
当我检查 MockRestServiceServer 的 verify 方法时,它没有调用 RequestMatchers 的 match 方法,我认为这个逻辑有问题。我在这里遗漏了什么吗?
/**
* Verify that all expected requests set up via
* {@link #expect(RequestMatcher)} were indeed performed.
* @throws AssertionError when some expectations were not met
*/
public void verify() {
if (this.expectedRequests.isEmpty() || this.expectedRequests.equals(this.actualRequests)) {
return;
}
throw new AssertionError(getVerifyMessage());
}
【问题讨论】:
标签: spring testing integration-testing spring-integration spring-test