0

我正在尝试使用带有 RestAssured 的 Cucumber Java 中的 Wiremock(独立)进行简单的存根。

stepdefinition我在课堂上有以下代码

    protected final int PORT = 8089;

    @Rule
    public WireMockRule wiremockRule = new WireMockRule(PORT);


    @Given("^mock environment has been setup$")
    public void mockEnvironmentHasBeenSetup() {

        stubFor(any(anyUrl()).willReturn(ok()));
    }

但它在上述方法中抛出并低于错误

wiremock.org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
    at wiremock.org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)

根据以下解决方案,这似乎是常见错误,但可能由于多种原因而发生。

序列问题
错误调用

POM.xml

<dependency>
    <groupId>com.github.tomakehurst</groupId>
    <artifactId>wiremock-jre8</artifactId>
    <version>2.26.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
</dependency>

就我而言,不太确定发生了什么。

第二种方法

我正在junit-jupiter-engine - 5.5.2使用wiremock 2.6.0

WireMockServer wireMockServer = new WireMockServer(wireMockConfig().port(8089));

        wireMockServer.start();
        int port = wireMockServer.port();
        wireMockServer.stubFor(any(anyUrl()).willReturn(ok()));
        System.out.println (port);
4

0 回答 0