Charles的mock技术小试牛刀
一、前言
在我们测试app的时候需要经常对一项功能的状态进行测试,比如有未过期、快过期和已过期等状态,直接修改数据库的数据字段是比较常见的一种手段,但是这种需要对表结构及相关表数据很熟悉,不然会修改出脏数据。那么有没有一种快捷有效可靠的方式呢,答案是有的,mock技术是一种很好的解决方案。
二、接口说明
三、相关业务状态说明
四、使用charles的Map Local功能mock各种response
1、mock为免费
{ "stateCode": 200, "stateMsg": "Success", "data": { "availableCount": 1, "serviceId": 1, "serviceStatus": 1, "storagePeriod": "30", "effectiveMonths": "1", "cameraCount": 1, "daysRemaining": 4, "expireTime": "2021-01-08 19:27:51", "isAlert": false, "trial": 1, "deviceVoList": [] } }
trial的值为1,并且serviceId也为1
output:
2、mock为付费
{ "stateCode": 200, "stateMsg": "Success", "data": { "availableCount": 1, "serviceId": 1006, "serviceStatus": 1, "storagePeriod": "30", "effectiveMonths": "1", "cameraCount": 1, "daysRemaining": 4, "expireTime": "2021-01-08 19:27:51", "isAlert": false, "trial": 2, "deviceVoList": [] } }
trial的值为2,并且serviceId为非1
output:
3、mock为免费快过期
{
"stateCode": 200,
"stateMsg": "Success",
"data": {
"availableCount": 1,
"serviceId": 1,
"serviceStatus": 1,
"storagePeriod": "30",
"effectiveMonths": "1",
"cameraCount": 1,
"daysRemaining": 4,
"expireTime": "2021-01-08 19:27:51",
"isAlert": true,
"trial": 1,
"deviceVoList": []
}
}
"stateCode": 200,
"stateMsg": "Success",
"data": {
"availableCount": 1,
"serviceId": 1,
"serviceStatus": 1,
"storagePeriod": "30",
"effectiveMonths": "1",
"cameraCount": 1,
"daysRemaining": 4,
"expireTime": "2021-01-08 19:27:51",
"isAlert": true,
"trial": 1,
"deviceVoList": []
}
}
trial的值为1,并且serviceId为1,isAlert为true
output:
4、mock为付费快过期
{ "stateCode": 200, "stateMsg": "Success", "data": { "availableCount": 1, "serviceId": 1006, "serviceStatus": 1, "storagePeriod": "30", "effectiveMonths": "1", "cameraCount": 1, "daysRemaining": 4, "expireTime": "2021-01-08 19:27:51", "isAlert": true, "trial": 2, "deviceVoList": [] } }
trial的值为2,并且serviceId为非1,isAlert为true
output:
5、mock为过期
{ "stateCode": 200, "stateMsg": "Success", "data": { "availableCount": 1, "serviceId": 1006, "serviceStatus": 2, "storagePeriod": "30", "effectiveMonths": "1", "cameraCount": 1, "daysRemaining": 4, "expireTime": "2021-01-08 19:27:51", "isAlert": true, "trial": 2, "deviceVoList": [] } }
serviceStatus为2
output:
如何使用Charles的Map Local功能请参考此篇文章
知道、想到、做到、得到