Postman 测试 - chai 断言的问题
Postman tests - problems with chai assertions
我在使用 postman 测试功能时遇到了一个奇怪的问题。
我曾经做过这样的测试:
tests["Status code is 200"] = responseCode.code === 200;
我需要稍微定制一下,所以我像这样升级了它:
test_name = "[ "+ request.name + " ] - ";
tests[test_name + "Status code is 200"] = responseCode.code === 200;
这有效。
我最近发现嵌入的代码段 "Status code: Code is 200" 会像这样显示:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
非常好,特别是一些用户没有开发背景,所以我试了一下,决定用它来测试。
然后我回到我原来需要定制的问题,所以我做了
pm.test(test_name + "Status code is 200", function () {
pm.response.to.have.status(200);
});
这不起作用,但它不会引发错误:测试根本没有出现在“测试”选项卡中!
之前我进行了测试 (3/3),其中 3 次测试通过,现在我进行了测试 (2/2)(至少我希望测试 (2/3) 有一次失败或错误)
这可能是我的语法,所以我尝试了不同的方法:
test_assert = test_name + "Status code is 200"
pm.test(test_assert, function () {
pm.response.to.have.status(200);
});
这也不行。
为了确保我的语法没有问题,我尝试了:
pm.test("[ Get all configuration - nominal ] - Status code is 200", function () {
pm.response.to.have.status(200);
});
失败。有字数限制吗???
为了检查目的,我尝试了
pm.test("[ Get all configuration - nominal ] - abcdefghijklmnopqrstuvwxyz0123456789", function () {
有效 => 这不是字符数限制,所以我尝试逐个字符地设置自己的字符串。
最高可达
pm.test("[ Get all configuration - nominal ] - Status code is 20", function () {
pm.response.to.have.status(200);
});
我完成了测试 (3/3)
如果我添加最后一个“0”它不起作用??????测试 (2/2)
我什至试过了:
pm.test("[ Get all configuration - nominal ] - Status code is 20 that's all", function () {
pm.response.to.have.status(200);
});
有效 :(
测试选项卡指示测试 (3/3),我有指示:
PASS [获取所有配置 - 标称] - 状态代码为 20 仅此而已
不知何故我进入暮光区了吗?
我想了解...我有任何想法
我找到了解决实际错误的方法
我尝试了更多测试:
检查问题是否以数字结尾:
pm.test("[ Get all configuration - nominal ] - Status code is 20 that's all0", function () {
pm.response.to.have.status(200);
});
=> 有效
查看是否链接到代码200的位置(我去掉了"nominal"最后的"l"):
pm.test("[ Get all configuration - nomina ] - Status code is 200", function () {
pm.response.to.have.status(200);
});
=> 失败
根据这一观察,我尝试在“200”之前插入一个或多个空格 space:
pm.test("[ Get all configuration - nominal ] - Status code is 200", function () {
pm.response.to.have.status(200);
});
=> 有效
无论“200”之前的 space 秒数如何,“测试”选项卡中的显示如下:
通过 [获取所有配置 - 标称] - 状态代码为 200
只有一个 space 在 "is" 和“200”
之间
我认为“测试”选项卡有一个棘手的错误。
这是一个真实的问题,因为在生产周期中,它可能会被忽视
我在使用 postman 测试功能时遇到了一个奇怪的问题。
我曾经做过这样的测试:
tests["Status code is 200"] = responseCode.code === 200;
我需要稍微定制一下,所以我像这样升级了它:
test_name = "[ "+ request.name + " ] - ";
tests[test_name + "Status code is 200"] = responseCode.code === 200;
这有效。
我最近发现嵌入的代码段 "Status code: Code is 200" 会像这样显示:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
非常好,特别是一些用户没有开发背景,所以我试了一下,决定用它来测试。 然后我回到我原来需要定制的问题,所以我做了
pm.test(test_name + "Status code is 200", function () {
pm.response.to.have.status(200);
});
这不起作用,但它不会引发错误:测试根本没有出现在“测试”选项卡中!
之前我进行了测试 (3/3),其中 3 次测试通过,现在我进行了测试 (2/2)(至少我希望测试 (2/3) 有一次失败或错误)
这可能是我的语法,所以我尝试了不同的方法:
test_assert = test_name + "Status code is 200"
pm.test(test_assert, function () {
pm.response.to.have.status(200);
});
这也不行。
为了确保我的语法没有问题,我尝试了:
pm.test("[ Get all configuration - nominal ] - Status code is 200", function () {
pm.response.to.have.status(200);
});
失败。有字数限制吗??? 为了检查目的,我尝试了
pm.test("[ Get all configuration - nominal ] - abcdefghijklmnopqrstuvwxyz0123456789", function () {
有效 => 这不是字符数限制,所以我尝试逐个字符地设置自己的字符串。 最高可达
pm.test("[ Get all configuration - nominal ] - Status code is 20", function () {
pm.response.to.have.status(200);
});
我完成了测试 (3/3)
如果我添加最后一个“0”它不起作用??????测试 (2/2)
我什至试过了:
pm.test("[ Get all configuration - nominal ] - Status code is 20 that's all", function () {
pm.response.to.have.status(200);
});
有效 :(
测试选项卡指示测试 (3/3),我有指示:
PASS [获取所有配置 - 标称] - 状态代码为 20 仅此而已
不知何故我进入暮光区了吗?
我想了解...我有任何想法
我找到了解决实际错误的方法
我尝试了更多测试:
检查问题是否以数字结尾:
pm.test("[ Get all configuration - nominal ] - Status code is 20 that's all0", function () { pm.response.to.have.status(200);
});
=> 有效
查看是否链接到代码200的位置(我去掉了"nominal"最后的"l"):
pm.test("[ Get all configuration - nomina ] - Status code is 200", function () { pm.response.to.have.status(200); });
=> 失败
根据这一观察,我尝试在“200”之前插入一个或多个空格 space:
pm.test("[ Get all configuration - nominal ] - Status code is 200", function () { pm.response.to.have.status(200); });
=> 有效
无论“200”之前的 space 秒数如何,“测试”选项卡中的显示如下:
通过 [获取所有配置 - 标称] - 状态代码为 200
只有一个 space 在 "is" 和“200”
之间我认为“测试”选项卡有一个棘手的错误。 这是一个真实的问题,因为在生产周期中,它可能会被忽视