【发布时间】:2018-11-11 18:33:57
【问题描述】:
- 使用 Postman 版本 v6.1.3 查看
- https://www.getpostman.com/docs/v6/postman/scripts/test_examples
第 1 部分
Postman 的测试示例包括此测试以查看是否存在标头:
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type");
});
我的响应标头包含以下内容:
Content-Type →application/json
我希望上面的测试能够通过,但它失败了。为什么? 它说:
FAIL Content-Type is present | AssertionError: expected response to not have header with key 'Content-Type'
此外,由于上述测试失败,那么我希望这个否定测试成功,但它也失败了:
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type");
});
上面写着:
FAIL Content-Type is present | AssertionError: expected response to not have header with key 'Content-Type'
请注意,这是与上述完全相同的错误消息。他们都说“没有预期的反应”,这对我来说似乎是错误的。
第 2 部分
为了让整个体验更加混乱,测试 key 和 value 字符串是可行的。我对“have.header”有什么误解吗?
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type →application/json");
});
返回:
PASS Content-Type is present
再一次,这个也通过了!
pm.test("Content-Type is present", function () {
pm.response.to.not.have.header("Content-Type →application/json");
});
返回:
PASS Content-Type is present
第 3 部分
帮助?!
【问题讨论】: