在 Postman 中,编写测试脚本通常使用 JavaScript,这些脚本可以在请求发送前后执行。以下是一些示例代码,展示了如何在 Postman 中使用测试脚本。
1. 测试脚本示例:检查响应状态码
// 测试脚本在请求发送后执行
pm.test("Response status code is 200", function () {
pm.response.to.have.status(200);
});
2. 测试脚本示例:检查响应体中的数据
// 测试脚本在请求发送后执行
pm.test("Response should have valid data", function () {
// 检查响应体是否包含特定的键
pm.response.to.have.jsonBo