利用Postman测试接口:

 

测试接口:

https://www.v2ex.com/api/topics/hot.json

 

添加断言:
 

tests['状态码必须是200'] = responseCode.code ===200;

var res = JSON.parse(responseBody);

console.log(res.length);

tests['必须返回9条数据'] = res.length ===9;

 

pm.test('返回正确的状态码',function(){

    pm.expect(pm.response).to.have.status(200)

    });

 

查看结果:

Postman测试接口添加断言

 

参考:

https://www.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference

 

相关文章: