gpt4 book ai didi

java - WireMock 有时表现得很奇怪

转载 作者:行者123 更新时间:2023-12-04 04:19:26 28 4
gpt4 key购买 nike

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

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

com.github.tomakehurst.wiremock.client.VerificationException:` com.github.tomakehurst.wiremock.client.VerificationException: com.github.tomakehurst.wiremock.client.VerificationException: No requests exactly matched. Most similar request was: expected:< POST /api/id/delete

but was:< POST /api/id/delete



正如您在上面看到的,预期端点与实际调用完全相同。

你有什么想法 ?或者你以前见过吗?
这里有一个 Unresolved 问题: https://github.com/tomakehurst/wiremock/issues/706 ,但回答不是很有帮助。

最佳答案

我在 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();
}
}

关于java - WireMock 有时表现得很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59768415/

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