【问题标题】:Tomakehurst Wiremock. Tries to connect to 8080. Connection refusedTomakehurst Wiremock。尝试连接到 8080。连接被拒绝
【发布时间】:2020-01-29 19:15:54
【问题描述】:
@Test
    void resourceTo_Wired_ClientCall() {

        wireMockServer = new WireMockServer(options().port(10021));
        wireMockServer.start();

            final MappingBuilder stubBuilder = get(urlMatching("http://demo1096495.mockable.io/client1"));

            stubFor(stubBuilder
                    .willReturn(aResponse()
                            .withStatus(200)
                            .withHeader("Content-Type", "application/json")
                            .withBody("{\"something\":\"test-wired\"}")));
            ;

出现错误:

org.apache.http.conn.HttpHostConnectException:连接到 localhost:8080 [localhost/127.0.0.1] 失败:连接被拒绝 (连接被拒绝)

遗漏了什么?

附:我使用WireMockServerjunit 5 和弹簧靴。 junit 4WireMockRule 都运行良好。

 testCompile "com.github.tomakehurst:wiremock-jre8:2.24.1"

【问题讨论】:

  • 在实际测试中你从哪里得到错误?您只发布了 Wiremock 设置。如果您的端口是 10021,为什么测试会尝试连接到 :8080?
  • 它发生在 stubFor(..) 上,为什么实际上是这个问题 :) (虽然使用 junit4 和 WireMockRule 配置效果很好)
  • 旁注:由于您使用stubFor 作为静态方法 - 您配置默认使用8080 端口的默认wiremock 实例。如果要为在测试中创建的实例创建存根,则应在实例上使用wireMockServer.stubFor

标签: java junit5 wiremock


【解决方案1】:

更新:

https://github.com/tomakehurst/wiremock/issues/369

已添加:WireMock.configureFor("localhost", 10021);

wireMockServer.start();之前

然后那个错误就消失了。它传递到下一行。

附: 有一些新东西..但这是不同的问题。

【讨论】:

    猜你喜欢
    • 2020-12-06
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 2011-07-26
    相关资源
    最近更新 更多