WireMock有时表现很怪异

问题描述 投票:2回答:1

[在大多数集成测试中,我使用spring-boot-test(2.1.9.RELEASE)和spring-cloud-contract-wiremock(2.0.2.RELEASE)。该测试基于@AutoConfigureWireMock(port = 0)启动WireMock服务器,因此我没有使用任何WireMockRule或其他配置设置。

有时验证失败并出现一个非常奇怪的错误:

com.github.tomakehurst.wiremock.client.VerificationException:`com.github.tomakehurst.wiremock.client.VerificationException:com.github.tomakehurst.wiremock.client.VerificationException:没有完全匹配的请求。最相似的请求是:预期:

但是是:

您可以在预期端点上方看到,与实际调用完全相同。

您有什么想法吗?还是您以前看过?这里有一个未解决的问题:https://github.com/tomakehurst/wiremock/issues/706,但是响应不是很有帮助。

java spring-boot-test wiremock
1个回答
0
投票

我在DELETE上也有同样的问题,但是在本地上它正在运行(windows + intelliJ),在Jenkins(linux)上却失败了。而你呢?

com.github.tomakehurst.wiremock.client.VerificationException: 
No requests exactly matched. Most similar request was:  expected:<
DELETE
/myAPI/api
> but was:<
DELETE
/myAPI/api
>

编辑:

解决方案:我的算法中有一个异步方法,不需要等待它完成算法,因此我必须放置Thread.sleep来确保调用已完成

    /**
     * Use It when you have a asyc call in your methode
     * @param delay time to wait
     */
    public void waitingForAsycRequest(int delay) {
            try {
                Thread.sleep(delay);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    }
© www.soinside.com 2019 - 2024. All rights reserved.