什么是断言?
写测试用例的时候都有预期结果。当执行测试的时候 预期结果与实际结果一致的情况下,接口用例通过,如果不一致,用例失败。
断言就是需要我们添加一些 预期结果与实际结果对比 代码,当预期结果与实际结果一致的时候,Postman 会生成测试报告。
断言 也就有 预期结果和实际结果的对比。
添加断言
在postman 中打开 Tests 面板
// 添加 状态码为 200 的断言pm.test("Status code is 200", function () {// 期望状态为200pm.response.to.have.status(200);});

添加json值对应的结果
// 期望 success的值为 truepm.test("success结果为true", function () {var jsonData = pm.response.json();// 设置实际运行结果 jsonData.success 预期结果为 truepm.expect(jsonData.success).to.eql(true);});

添加完成断言之后,在 runner中执行,可以看到执行的结果。
总结
给接口添加断言,下次做回归测试的时候,可以在runner直接批量运行,直接查看运行结果。可以提高工作效率。

作业:
接口练习: http://47.100.175.62:3000/api
要求:
- 有上下游关联的业务场景 使用 变量传参
- 必要的接口添加对应的断言。
数据库作业
主机地址:rm-bp188nr95fk4l9545ao.mysql.rds.aliyuncs.com端口号:3306用户名:abtester密码:123@abtester
- 查询语文成绩大于数学成绩的同学;
分别将
语文成绩 查询出来 作为一张表 a
数学成绩 查询出来 作为一张表 b
学生信息 c
将这三张表关联到一起进行内联查询
select sname ,a.score as 语文,b.score as 数学from(select sno,score from scorewhere cno ="yw")ainner join(select sno,score from scorewhere cno="sx")bon a.sno=b.snoinner join students c on a.sno=c.snowhere a.score >b.score
<开放题>登录数据库
主机地址:rm-bp188nr95fk4l9545ao.mysql.rds.aliyuncs.com端口号:3306用户名:fanmao65密码:abc@fanmao65数据库:fanmao65_hm
- 给你一个这样的数据库表数据 | Y | M | Amount | | —- | —- | —- | | 2020 | 1 | 101 | | 2020 | 2 | 102 | | 2020 | 3 | 103 | | 2021 | 1 | 201 | | 2021 | 2 | 202 | | 2021 | 3 | 203 |
请写一个SQL,得出如下结果:
| Y | M1 | M2 | M3 |
|---|---|---|---|
| 2020 | 101 | 102 | 103 |
| 2021 | 201 | 202 | 203 |

select Y,max(case M when 1 then Amount else 0 end) as M1,max(case M when 2 then Amount else 0 end) as M2,max(case M when 3 then Amount else 0 end) as M3from ymagroup by Y
select y,(select Amount from yma m where m=1 and m.y=yma.y) as m1,(select Amount from yma m where m=2 and m.y=yma.y) as m2,(select Amount from yma m where m=3 and m.y=yma.y) as m3from yma group by y;
