3.24-3 接口测试断言

一.postman 断言

1.断言再test中

#状态码是否等于200

tests"Status code is 200" = responseCode.code === 200;

#断言响应时间小于200ms

tests"Response time is less than 200ms" = responseTime < 200;

#断言响应体包含内容

tests"Body matches string" = responseBody.has("string_you_want_to_search");

查看断言结果

如果不断言,只能说明接口是通的,不能说明响应体是正确的

认识下test中的功能

postman.clearGlobalVariable("variable_key");

postman.clearEnvironmentVariable("variable_key");

tests"Body matches string" = responseBody.has("string_you_want_to_search");

var jsonObject = xml2Json(responseBody);

tests"Body is correct" = responseBody === "response_body_string";

var jsonData = JSON.parse(responseBody);

tests"Your test name" = jsonData.value === 100;

tests"Content-Type is present" = postman.getResponseHeader("Content-Type");

tests"Response time is less than 200ms" = responseTime < 200;

postman.setGlobalVariable("variable_key", "variable_value");

postman.setEnvironmentVariable("variable_key", "variable_value");

tests"Status code is 200" = responseCode.code === 200;

tests"Status code name has string" = responseCode.name.has("Created");

tests"Successful POST request" = responseCode.code === 201 || responseCode.code === 202;

var schema = {

"items": {

"type": "boolean"

}

};

var data1 = true, false;

var data2 = true, 123;

tests"Valid Data1" = tv4.validate(data1, schema);

tests"Valid Data2" = tv4.validate(data2, schema);

console.log("Validation failed: ", tv4.error);

相关推荐
瑞码空间6 分钟前
Python爬虫进阶实战笔记
开发语言·python·计算机·python爬虫
16月6日-晴14 分钟前
Java面向对象进阶—static
java·开发语言
爱跳舞的烤冷面15 分钟前
自学嵌入式第16天(数据结构篇--链表进阶操作)
开发语言
持敬chijing27 分钟前
PHP开发-环境搭建-安装phpstudy-vscode工具
开发语言·vscode·php
charlie1145141911 小时前
Cinux · 第一次跳进 Ring 3:用户态与特权隔离
开发语言·c++·操作系统·开源项目
躺不平的理查德1 小时前
Windows C++ 第三方库使用流程备忘录--OpenCV
开发语言·c++
菜冻鱼2 小时前
Python-sklearn-评估指标
开发语言·人工智能·python·机器学习·numpy·pandas·sklearn
你挚爱的强哥2 小时前
【exportExcel】单纯靠js不用任何其他第三方插件导出xls格式文件
开发语言·javascript·ecmascript
Hello_Damon_Nikola2 小时前
AC7911从入门到精通
开发语言·嵌入式硬件·物联网·php
worxfr2 小时前
Go 并发控制:从 Channel 方向约束到实战模式
开发语言·后端·golang