一、测试内容
1、功能描述
APP的社区首页动态如果有关联商品则在图片上展示单品icon
社区首页动态内容添加一个字段:hasRelatedGoods
2、接口介绍
community.getDiscovery

3、返回结果

二、postman中配置请求内容
1、配置环境变量
目的:测试过程中有内测、外测、生产环境,设置环境变量只要切换就可以请求不同的url

2、添加请求
环境变量直接用{{url}}+其他请求内容


三、postman中写Tests
1、写断言,就是要测试的内容
这里用到了三个
①、请求是否成功,状态码是否为200
②、返回的hasRelatedGoods和预期的是否一致
③、返回的动态个数是否为20
//返回的状态码判断
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
//获取数组的长度
pm.test("一页返回的article数是否为20",function () {
var jsonData = pm.response.json();
var articleCount = jsonData.data.list.length;
console.log(articleCount);
pm.expect(articleCount).to.eql(20);
});
//比对某个字段值和预期是否相等
pm.test("第1个动态的hasRelatedGoods是否为1", function () {
var jsonData = pm.response.json();
var hasRelated = jsonData.data.list[0].hasRelatedGoods;
var articleId = jsonData.data.list[0];
console.log(articleId);
pm.expect(hasRelated).to.eql(1);
});
////比对某个字段值和预期是否相等
pm.test("第20个动态的hasRelatedGoods是否为0", function () {
var jsonData = pm.response.json();
var hasRelated = jsonData.data.list[19].hasRelatedGoods;
var articleId = jsonData.data.list[19];
console.log(articleId);
pm.expect(hasRelated).to.eql(0);
});
2、执行
①返回的状态码为200,所以通过
②获取的长度为21个,预期结果20,所以未通过
③list中第1个article的hasRelatedGoods为1,和预期结果一致,通过
④list中第20个article的hasRelatedGoods为0,和预期结果一致,通过

S
四、日志分析
上面的Tests中有打印日志内容,,为了看获取的内容的详细信息点击左下角可以查看日志
console.log(articleCount);
console.log(articleId);
console.log(articleId);

五、常用断言
待补充。。。
网友评论