Spring MockRestServiceServer处理对同一URI的多个请求(自动发现)

Spring MockRestServiceServer处理对同一URI的多个请求(自动发现),第1张

Spring MockRestServiceServer处理对同一URI的多个请求(自动发现)

如果您查看MockRestServiceServer类,它支持两个“
expect()”方法。第一个默认为’ExpectedCount.once()’,但是第二个方法允许您更改此值

public ResponseActions expect(RequestMatcher matcher) {    return this.expect(ExpectedCount.once(), matcher);}public ResponseActions expect(ExpectedCount count, RequestMatcher matcher) {    return this.expectationManager.expectRequest(count, matcher);}

我发现此票证MockRestServiceServer应该允许多次出现期望,其中概述了第二种方法的一些选项

在您的情况下,我认为添加静态导入并使用manyTimes()方法比for循环更整洁。

MockRestServiceServer .expect(manyTimes(), requestContainsUri("/stuff")) .andExpect(method(HttpMethod.GET))

其他选项是

once();manyTimes();times(5);min(2);max(8);between(3,6);


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5621855.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存