gpt4 book ai didi

java - WireMock stub 创建失败 : expects 201 but gets 200

转载 作者:行者123 更新时间:2023-11-30 03:27:13 30 4
gpt4 key购买 nike

我是 WireMock 的新手,并试图让我的第一个单元测试能够使用它。现在,按照wiremock.org 上的文档,我写了这个

    WireMockConfiguration config = wireMockConfig().port(9089).httpsPort(8443);
m_wireMockServer = new WireMockServer(config);

m_wireMockServer.start();
WireMock.configureFor("localhost", 9089);
givenThat(get(urlEqualTo("/some/thing"))
.willReturn(aResponse()
.withHeader("Content-Type", "text/plain")
.withBody("Hello world!")));

我希望这会使任何对/some/thing 的 http 请求被捕获。它在给定的调用中给了我以下异常:

com.github.tomakehurst.wiremock.client.VerificationException: Expected status 201 for http://localhost:9089/__admin/mappings/new but was 200
at com.github.tomakehurst.wiremock.client.HttpAdminClient.postJsonAssertOkAndReturnBody(HttpAdminClient.java:151)
at com.github.tomakehurst.wiremock.client.HttpAdminClient.addStubMapping(HttpAdminClient.java:65)
at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:130)
at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:126)
at com.github.tomakehurst.wiremock.client.WireMock.givenThat(WireMock.java:65)

我错过了什么?创建 stub 时出了什么问题?

最佳答案

我的猜测是,您在测试运行之间始终让 Wiremock 在后台运行,因此当您在测试中设置新映射时,该映射并不是真正的新映射,因为已经存在一个现有映射并且 Wiremock 会做出响应200(确定)而不是 201(已创建)。

为了测试这一假设,请尝试在分配给 Wiremock 的端口上找到进程,如果有,则终止它并再次运行测试。

关于java - WireMock stub 创建失败 : expects 201 but gets 200,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29921899/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com