java - Wiremock 查询参数 JSON stub 文件

标签 java stub wiremock

我正在尝试使用 wiremock JSON stub 文件模拟查询参数。

当我这样做时它会起作用:

{
  "request": {
    "method": "GET",
    "url": "/posts?id=1",
  },
//...
}

但是,当我更改查询参数以使用这样的专用字段时,它不再起作用:
{
  "request": {
    "method": "GET",
    "urlPath": "/posts",
    "queryParameters": {
      "id": {
        "equalTo": "1"
      }
    }
  },
  //...
}

知道为什么吗?

测试请求看起来像 http://some-host/posts?id=1

最佳答案

这对我有用,将您的 "urlPath" 更改为 "urlPathPattern" 但在构建此 JSON 时要小心。所以 urlPath 是精确匹配模式,但 urlPathPattern 是路径和查询参数上的正则表达式匹配

  {
        "request": {
            "urlPathPattern": "/posts",
            "method": "GET",
            "queryParameters": {
                "id": {
                    "equalTo": "1"
                }
            }
        },
        "response": {
            "status": 200,
            "body":"This is successful"
        }
    }

关于java - Wiremock 查询参数 JSON stub 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50523008/

相关文章:

postman - API端点通过Postman通过POST方法保存多部分文件

android - 在 Android 集成测试中使用 WireMock 时出现 NoSuchMethodError

java - spring integration tcp客户端发送简单消息

java - Android Studio - 从 GetIdToken 获取 Firebase token

java - "No row with the given identifier exists"虽然它确实存在

java - 格式化 TextWatcher android

node.js - 为什么 sinon 不取代实际的函数调用?

intellij-idea - 结合模拟和 stub 时对 Spock 交互的 IntelliJ 警告

java - Wiremock 对同一请求的不同响应

java - Android 测试不会在低于 5 (API 21) 的设备上运行 NoClassDefFoundError