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);

相关推荐
slandarer1 小时前
MATLAB | 韦恩图的高阶版: UpSet图 更新升级啦!
开发语言·matlab
Leweslyh1 小时前
3GPP TS 28.312 意图驱动管理服务 — 极详细通俗解读
开发语言·php
swordbob1 小时前
Spring事务失效的场景
java·开发语言·spring
catchadmin2 小时前
PHP 在领域驱动(DDD)设计中的核心实践
开发语言·php
SilentSamsara2 小时前
MLflow 实验追踪与模型注册:从实验到生产的可复现工作流
开发语言·人工智能·pytorch·python·青少年编程
dongf20192 小时前
R语言朴素贝叶斯算法---iris数据集
开发语言·算法·数据分析·r语言
下班走回家2 小时前
RAG 技术的进化:从朴素检索到 Agentic RAG
开发语言·人工智能·python
weixin_307779132 小时前
从“大海捞针”到“主动推理”:AI如何重塑云原生故障诊断的根因链
开发语言·人工智能·算法·自动化·原型模式
Johnstons2 小时前
网页加载到一半卡住?视频看到关键处花屏?可能是丢包在作祟
开发语言·php·音视频·弱网测试·网络损伤
hoiii1872 小时前
C# Txt/Excel/Access 导入导出工具
开发语言·c#·excel