邮递员不接受将-用作模拟服务器请求的URI参数

时间:2020-01-15 12:28:32

标签: unit-testing request mocking postman

我收到以下错误响应:

{
    "error": {
        "name": "mockRequestNotFoundError",
        "header": "No matching requests",
        "message": "Double check your method and the request path and try again."
    }
}

当我将-作为通过模拟服务器创建的Postman请求的URI参数传递时,与我在未通过模拟服务器创建的请求中传递相同的URI参数值时,它运行良好!

URL:http://{{host}}/order/{{subUserId}}/{{BusinessDate}}/5

主机:{mocking-server-url-without-http-keyword}

subUserId:1

BusinessDate:2020-01-12-17-07-21

HTTP请求标头:x-api-key{{postman_secret_API_key}}

通过使用模拟服务器作为主机来正确返回数据的主要请求:

enter image description here

通过使用模拟服务器作为主机来返回错误的模拟请求:

enter image description here

1 个答案:

答案 0 :(得分:0)

模拟example需要匹配主请求的路径才能返回。

例如:

enter image description here

否则,将无法找到您正在使用的模拟example

enter image description here

我不确定您的特定上下文,但是您也可以在主要请求中使用不同的Request Headers来指向特定的模拟示例:

x-mock-response-code:200
x-mock-response-name:<name of the mock example>