Wiremock 响应的链接

Chaining of Wiremock Responses

我目前正在开发 Spring 启动应用程序。作为其中的一部分,我一直在使用 TDD 来证明我的更改是正确的。为此,我使用 Wiremock 复制外部 API。我想知道是否可以像使用 Mockito 一样链接多个响应(如下所示):

when(myMock.doTheCall())
.thenReturn("You failed")
.thenReturn("Success");

WiremockRule 会有类似的东西吗?

通常 WireMock 将 return 以相同方式匹配任何请求的相同响应。如果您希望第二次有不同的响应,则必须使用有状态行为: http://wiremock.org/docs/stateful-behaviour/ . Another alternative is to generate dynamic responses with the help of extensions: http://wiremock.org/docs/extending-wiremock/

所以你的问题的答案是NO,不是现成的。

如果您的测试因此而变得笨拙,您可能想要围绕 WireMock 提取一些 helpers/wrappers。