测试简介
测试对象是服务器后端,采用白盒测试,以达到高代码覆盖率。
测试环境与工具
nodejs+postman
测试方式
- 单元测试:针对各个用例的源代码,编写测试用例,分别在测试路径和生产环境路径下进行较为简略和较为详细的测试。
- 压力测试:针对每个测试单元进行短期内超量请求的测试,以探测系统的漏洞和极限。
测试流程
- 在Body中确定发送请求的字段,并将其值修改为变量的形式
- 在Pre-request Script中,对变量进行赋值
- 在Tests中,编写测试条件
- 在csv文件中,准备测试样例
- 点击run,选择外部数据文件和循环次数,开始测试。
测试用例(以用户注册为例)
生产环境路径
用户相关
1.用户注册
-
id格式检测
-
测试样例
uid,uname,uemail,upassword,uphone,ustatus "1111111","hhh","222@22.com","123456",11111111111,"student" "1111a11","hhh","222@22.com","123456",11111111111,"student" "aa1","hhh","222@22.com","123456",11111111111,"student" "aaaaaaaaaaa1","hhh","222@22.com","123456",11111111111,"student"
-
检测条件
pm.test("id格式错误", function () { var jsonData = JSON.parse(responseBody); console.log(responseBody) pm.expect(jsonData.msg).to.eql("The id format is incorrect(6-8 letter or digit, begin with letter)"); });
- 测试结果
-
测试总结
测试内容 通过(Y/N) id必须包含字母 Y id必须以字母开头 Y id不得小于6位 Y id不得大于8位 Y -
测试说明
一切正常。
-
-
电话格式检测
-
测试样例
uid,uname,uemail,upassword,uphone,ustatus "aaaaaa1","hhh","222@22.com","123456",1111111a111,"student" "aaaaaa1","hhh","222@22.com","123456",01111111111,"student" "aaaaaa1","hhh","222@22.com","123456",1111111111,"student" "aaaaaa1","hhh","222@22.com","123456",111111111111,"student"
-
检测条件
pm.test("电话格式错误", function () { var jsonData = JSON.parse(responseBody); console.log(responseBody) pm.expect(jsonData.msg).to.eql("The phone format is incorrect(11 digit number, begin with ~0"); });
-
测试结果
-
测试总结
测试内容 通过(Y/N) 电话不能包含字母 Y 电话必须以0开头 Y 电话不得小于11位 Y 电话不得大于11位 Y -
测试说明
一切正常。
-
-
邮箱格式检测
-
测试样例
uid,uname,uemail,upassword,uphone,ustatus "aaaaaa1","hhh","22222.com","123456",11111111111,"student" "aaaaaa1","hhh","222@22com","123456",11111111111,"student" "aaaaaa1","hhh","@22.com","123456",11111111111,"student" "aaaaaa1","hhh","222@22.","123456",11111111111,"student" "aaaaaa1","hhh","222@.com","123456",11111111111,"student"
-
检测条件
pm.test("邮箱格式错误", function () { var jsonData = JSON.parse(responseBody); console.log(responseBody) pm.expect(jsonData.msg).to.eql('The email format is incorrect(XXX@XXX.XXX)'); });
-
测试结果
-
测试总结
测试内容 通过(Y/N) 邮箱必须包含@ Y 邮箱必须包含. Y 邮箱@之前要有东西 Y 邮箱.之后要有东西 Y 邮箱.和@之间要有东西 Y -
测试说明
一切正常。
-
-
密码格式检测
-
测试样例
uid,uname,uemail,upassword,uphone,ustatus "aaaaaa1","hhh","222@22.com","123",11111111111,"student" "aaaaaa1","hhh","222@22.com","123456123456123",11111111111,"student"
-
检测条件
发现写了密码的判断函数,但是没有在路由中进行判断,之后对其进行补充并测试。
if(!validator.checkPhone(req.body.password)) { utils.sendError(res, 400, "The password format is incorrect(6~12 digit number)"); return; }
pm.test("密码格式错误", function () { var jsonData = JSON.parse(responseBody); console.log(responseBody) pm.expect(jsonData.msg).to.eql("The password format is incorrect(6~12 digit number)"); });
-
测试结果
-
测试总结
测试内容 通过(Y/N) 密码不得小于6位 Y 密码不得大于12位 Y -
测试说明
修改之后一切正常。
-
-
重复输入检测
-
测试样例
数据库中已存在的数据:
uid,uname,uemail,upassword,uphone,ustatus "test1","hhh","22222.com","123456","11111111111","student" "aaaaaa1","hhh","12345678@qq.com","123456","11111111111","student" "aaaaaa1","hhh","222@22.com","123456","12345678910","student"
-
检测条件
pm.test("插入失败", function () { pm.expect(pm.response.code).to.be.oneOf([400]); });
-
测试结果
-
测试总结
测试内容 通过(Y/N) id不可重复 Y 电话不可重复 Y 邮箱不可重复 Y -
测试说明
一切正常。
-
-
压力测试
-
测试条件
测试三百次
pm.test("插入失败", function () { pm.expect(pm.response.code).to.be.oneOf([400]); }); pm.test("响应时间小于 200ms", function () { pm.expect(pm.response.responseTime).to.be.below(200); });
-
测试结果
-