【接口测试框架】ApiTestForHttp(3)- 如何编写一
2019-10-16 本文已影响0人
金鱼座
大家好,我是金鱼座,一个走在测试领域这片蓝海中, 蹉跎前行的技术渣渣,唯有一直走下去,也许能改变点什么,加油!
ATFH(ApiTestForHttp)支持对于单接口的api测试,也支持对于流程性接口的相关数据流业务的测试工作,请看下面
1、 单接口api的用例编写
{
"name": "编辑子园区", # json测试名称
"type": "api", #测试用例类型(单接口|流程性业务)
"author": "王慧", # 用例编写人员
"date": "19/02/14", #json文件编写时间
"test": [{
"name": "login_commuity_with_jack_中文", #接口测试点描述
"setup": { # 接口数据预设准备(主要是做数据准备)
"username": "jack1"
},
"requestor":{ #api相关信息
"url": "${host}/${customer}/device-mgr/api/auth/login",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"data": { "username": "${username}", "password": "111111"}
},
"validator": { # 校验接口返回值
"assertEqCode": 200,
"assertEqHeaders": {"Content-Type": "application/json;charset=UTF-8"},
"assertEqStr": ["100000"],
"assertEqJson":{"success":true}
},
"collector":{ #收集接口响应
"json": {"admintoken": "response.data.token"}
},
"teardown":{} #清理setup中的内容
}]
}
2, 业务流程性case
{
"name": "测试登录场景",
"type": "scene",
"author": "王慧",
"date": "19/02/14",
"test": [
{
"name": "denglu1",
"setup": {
"num1":123,
"username": "tuni",
"data2": { "username": "${username}", "password": "123456"}
},
"requestor":{
"url": "${host}/device-mgr/api/auth/login",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"data": "${data2}"
},
"validator": {
"assertEqCode": 200,
"assertEqHeaders": {"Content-Type": "application/json;charset=UTF-8"},
"assertEqStr": ["100000"],
"assertEqJson":{
"success":true
}
},
"collector":{
"json": {
"supertoken": "response.data.token"
}
},
"teardown":{}
},
{
"name": "denglu2",
"setup": {
"num1":123,
"username": "tuni",
"data2": { "username": "${username}", "password": "123456"}
},
"requestor":{
"url": "${host}/device-mgr/api/auth/login",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"data": "${data2}"
},
"validator": {
"assertEqCode": 200,
"assertEqHeaders": {"Content-Type": "application/json;charset=UTF-8"},
"assertEqStr": ["100000"],
"assertEqJson":{
"success":true
}
},
"collector":{
"json": {
"supertoken": "response.data.token"
}
},
"teardown":{}
}]
}
单接口和业务流程性case的区别在于,type为api和scene,另外就是test中api为单个api,而scene中为多个api
框架还存在大量的重复内容, 待后续在进行优化