java - 使用 WireMock 请求订单验证

标签 java wiremock

我有一个 API,我应该按特定顺序多次 PUT 。我正在使用 WireMock 测试我的客户端,我想在测试中检查请求是否按正确的顺序发出。

由于此 API 将返回 204 No Content,因此我的代码不需要先前请求的结果来发出下一个请求,这似乎排除了 WireMock 场景。

那么,WireMock 是否有类似于 Mockito 的 inOrder 的功能?

最佳答案

这可以通过WireMock Scenario来实现功能,文档中的示例:

For example, suppose we’re writing a to-do list application consisting of a rich client of some kind talking to a REST service. We want to test that our UI can read the to-do list, add an item and refresh itself, showing the updated list.

{
    "scenarioName": "To do list",
    "requiredScenarioState": "Started",
    "request": {
        "method": "GET",
        "url": "/todo/items"
    },
    "response": {
        "status": 200,
        "body" : "<items><item>Buy milk</item></items>"
    }
}

{
    "scenarioName": "To do list",
    "requiredScenarioState": "Started",
    "newScenarioState": "Cancel newspaper item added",
    "request": {
        "method": "POST",
        "url": "/todo/items",
        "bodyPatterns": [
            { "contains": "Cancel newspaper subscription" }
         ]
    },
    "response": {
        "status": 201
    }
}

{
    "scenarioName": "To do list",
    "requiredScenarioState": "Cancel newspaper item added",
    "request": {
        "method": "GET",
        "url": "/todo/items"
    },
    "response": {
        "status": 200,
        "body" : "<items><item>Buy milk</item><item>Cancel newspaper subscription</item></items>"
    }
}

关于java - 使用 WireMock 请求订单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55476553/

相关文章:

java - 多个 Web 服务的 stub 策略?

java - WildFly 与 Payara JSON 响应——什么是标准行为?

java - 哪些 Java 语言机制允许对象引用变量类型与其引用的对象类型不同?

Java ASM如何读取LOAD或STORE字节码的值

xamarin - 如何在 Xamarin.UITest 项目中使用 WireMock.Net?

java - Wiremock 日期格式

java - JList 中的 ActionListener 出现 ArrayIndexOutOfBoundsException

Java : Selection Sort Logic

java - WireMock 中的查询参数

java - Angular http 到 Wiremock stub 使用 200 选项而不是删除 -> 页面继续 onRejected