java - 同时进行Wiremock记录和存根
问题描述
我有一个服务(A)调用另一个服务(B),我正在用 Wiremock 模拟它。我想做的是做一个测试:
- 如果我处于录音模式,请记录呼叫 A -> B 并将它们放入文件中
- 如果我处于非录音模式,则捕获呼叫 A -> B 并将它们与预先录制的模拟进行比较(这就像回归测试)
我当前的结构是 BMockRule.java
public class BMockRule extendsWireMockClassRule {
public BMockRule(Options options) {
super(options);
}
@Override
protected void before() {
super.before();
this.stub();
}
@Override
public void stub() {
this.stubFor(requestMatching(request ->
MatchResult.of(request.getUrl().contains("/request")))
.willReturn(aResponse().withStatus(200))
);
}
}
我的测试里面看起来像
public class QuoteCachePublisherIntTest {
@ClassRule
public static DropwizardAppRule<MicroServiceConfiguration> rule =
new DropwizardAppRule<>(
MicroServiceApplication.class,
resourceFilePath("test_config.yml"));
private QuoteCachePublisher publisher;
@ClassRule
public static BasicWiremockClassRule serviceB =
new BMockRule(options().port(5100)).withStatus(200);
@Test
public void test_Request() {
if(record) {
WireMock.startRecording("http://localhost:5100");
}
publisher.publish(parameters);
if(record) {
SnapshotRecordResult recordedMappings = WireMock.stopRecording()
<write-stubs-to-file>
} else {
SnapshotRecordResult recordedMappings = <read-stubs-from-file>
}
// verify statements that compare the actual calls vs the recorded mappings
}
问题是,当我进行录制时,存根不起作用。有没有一种简单的方法可以做到这一点。
谢谢 :)
解决方案
推荐阅读
- typescript - Svelte 组件作为对象属性
- python-3.x - 将 SECRET_KEY 放入 .env 文件中的填充错误不正确
- java - 无法使用 NTriples (OWLAPI) 保存本体
- html - 在 iOS 应用程序中使用 XSLT 样式表从 XML 生成 HTML
- c# - InvalidOperationException:尚未为“/Views/_ViewImports.cshtml”处的页面调用 RenderBody。忽略调用 IgnoreBody()
- android - 在不使用 ADB 的情况下通过 USB 将数据从 Android 发送到 Windows
- java - 带有空正文响应的问题改造 Post API
- .net - 如何让应用程序在 WinPE 中运行?
- python - 当用户@the bot 时,Discord.py bot 不读取
- python - 提交“g-recaptcha-response”的文本区域不起作用 Selenium 和 Python