我是WireMock的新手,试图让我的第一个单元测试与它一起工作。现在,继Wiremock.org上的文档,我写了这个WireMock存根创建失败:期望201但得到200
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!")));
我希望这可以让任何http请求被/抓到/ some/thing。它给了我在拨打电话的以下例外:
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)
我错过了什么?存根的创建有什么问题?
让我们从这里的网址差异开始。 get方法调用中的URL与断言失败的URL不同。 – Makoto
是的,我想要使用/ some/thing的模拟行为的测试甚至没有在这里开始。我想要得到/ some/thing的行为,就像我为测试定义的那样。但是这种行为的注册会发生异常。注册返回200,但需要201,因为我的理解很好。 – Jos