java接口自动化系列(02):测试数据文件设计(excel/yaml)
本系列汇总,请查看这里:https://www.cnblogs.com/uncleyong/p/15867903.html
实现目标
对测试数据进行设计,数据设计决定了后续读取数据的代码该如何实现。
关于被测试接口
配套练习环境(含相关接口):https://www.cnblogs.com/uncleyong/p/17165143.html
创建测试数据文件
目录caseData下创建数据文件

说明:本次优先分享的是测试数据存excel中,文末有yaml数据样例
常用数据
用例数据频繁使用到的值,我们可以放到一个变量中,这样避免修改值的时候大面积修改
示例
sheet名称:variables

解释:标题行
每个单词首字母大写,因为代码里面反射会用到
解释:字段数据
Name:变量名,#{xxx}整体表示变量名
Value:变量值
Description:变量的描述
测试用例数据
示例
sheet名称:case


解释:标题行
每个单词首字母大写,因为代码里面反射会用到
解释:字段数据
Url:只写路径,不需要写ip、端口
RequestType:目前只支持post、get
Headers:json格式字符串,如果没有请求头,填写为{}
Cookies:预留,暂未使用
Parameters:json格式字符串,如果是非关联变量(也就是上面的常用变量),填写为#{xxx},如果是关联参数,填写为${xxx}
UploadFile:预留,暂未使用
InitSql:初始化sql,要求是json数组,例如:[{"sqlNo":"1","sql":"delete from users where username = '#{username}';"}],用到的常用变量,填写为#{xxx}
GlobalVariables:需要关联的参数值,样例:token=$.token;,左侧是字段名,右侧是其jsonpath路径,并以英文分号结尾,多个断言字段用英文分号间隔
AssertFields:要断言字段的jsonpath路径以及值,并以英文分号结尾,多个断言字段用英文分号间隔,如:
$.code=9550;$.msg=success;
补充:测试数据存yaml
caseData.yaml,和上面excel中测试数据一样
---
- caseId: 1
apiName: register
describe: 注册
url: /qzcsbj/user/register
requestType: post
headers: {'Content-Type':'application/json'}
cookies:
parameters: {"username":"#{username}","password":"#{password_correct}","realName":"#{username}","sex":"1","birthday":"1990-06-16","phone":"13500000006","utype":"1","adduser":"#{username}"}
uploadFile:
initSql: [{"sqlNo":"1","sql":"delete from user where username = '#{username}';"}]
globalVariables:
assertFields: $.msg=注册成功;
- CaseId: 2
ApiName: login
Describe: 登录
Url: /qzcsbj/user/login
RequestType: post
Headers: {"Content-Type":"application/json"}
Cookies:
Parameters: {"username":"#{username}", "password":"#{password_correct}"}
UploadFile:
InitSql:
GlobalVariables: token=$.data.token;
AssertFields: $.msg=登录成功;
- CaseId: 3
ApiName: add
Describe: 添加商品
Url: /qzcsbj/product/add
RequestType: post
Headers: {"Content-Type":"application/json"}
Cookies:
Parameters: {"product":{"price":9999,"productName":"#{productname}"},"token":"${token}"}
UploadFile:
InitSql: [{"sqlNo":"1","sql":"delete from product where product_name = '#{productname}';"}]
GlobalVariables:
AssertFields: $.msg=添加商品成功;
- CaseId: 4
ApiName: findByName
Describe: 查询商品
Url: /qzcsbj/product/findByName
RequestType: get
Headers: {}
Cookies:
Parameters: {"name":"#{productname}"}
UploadFile:
InitSql:
GlobalVariables:
AssertFields: $.msg=查询商品成功;
- CaseId: 5
ApiName: findByName
Describe: 查询商品
Url: /qzcsbj/product/findByName
RequestType: get
Headers: {}
Cookies:
Parameters: {"name":"#{productname}"}
UploadFile:
InitSql:
GlobalVariables:
AssertFields: $.msg=查询商品成功啦;
yaml数据校验

__EOF__
关于博主:擅长性能、全链路、自动化、企业级自动化持续集成(DevTestOps)、测开等
面试必备:项目实战(性能、自动化)、简历笔试,https://www.cnblogs.com/uncleyong/p/15777706.html
测试提升:从测试小白到高级测试修炼之路,https://www.cnblogs.com/uncleyong/p/10530261.html
欢迎分享:如果您觉得文章对您有帮助,欢迎转载、分享,也可以点击文章右下角【推荐】一下!

浙公网安备 33010602011771号