Postman接口测试工具
添加断言Tests
1、检查响应时间
tests['Response time is less than 200ms'] =responseTime < 200;
2、检查状态码
tests['Status code'] =responseCode.code===200;
3、检查响应body中包含字段
tests['Response body has string'] =responseBody.has('string');
4、检查name中包含字段
tests['Status code name has string'] =responseCode.name.has('string');
5、检查响应头中的某个元素是否存在
tests['Connection is present'] =postman.getResponseHeader('connection');
6、检查POST 请求的状态响应码
tests['Post response code'] =responseCode.code===201 || responseCode.code===202;
(未完待续,后续再详细更新)
ps附上所有方法,官方文档
地址:https://learning.getpostman.com/docs/postman/scripts/test_examples/