自动化用例的自动生成技术
作者:网络转载 发布时间:[ 2013/1/21 11:15:31 ] 推荐标签:
比如,我们想要获取user的预期取值范围,代码可以这么写:
public BaseUserDO getExpectUser(String nick){
//给取值范围里的nick分组,只有在这个组里面的用户才存在,否则均返回null
String[] exsitUserNicks= {Nick.b2bNick.value, Nick.subB2BNick.value};
if(ArrayUtil.contains(exsitUserNicks, nick)){
//根据nick查出用户信息返回
ResultDO<BaseUserDO> callback = uicReadServiceClient.getUserInfoByNick(nick);
Assert.assertTrue(callback.getErrMsg(), callback.isSuccess());
Assert.assertNotNull(callback.getModule());
return callback.getModule();
}
return null;
}
代码中“Nick.b2bNick.value”,Nick是一个枚举,方便输入数据值域归类:
public enum Nick{
blankNick(""),
nullNick(null),
notExsitNick("1233211"),
tbNick("leizang_test"),
b2bNick("leizang_btob_1"),
subB2BNick("leizang_btob_1:subnick01");
String value;
Nick(String value){
this.value= value;
}
}
类似地,我们需要编写如下方法:
中间对象 |
被依赖对象 |
编写获取方法(省去类型) |
user |
nick |
getExpectUser(nick) |
ruleCode |
user, wwLimitData |
getExpectRuleCode(user, wwLimitData) |
isFrozen |
user, wwLimitData |
getExpectIsFrozen(user, wwLimitData) |
suspended |
user, isFrozen |
getExpectSuspended(user, isFrozen) |
punishData |
user, punishData, suspended |
getExpectPunishData(user, punishData, suspended) |
mmpData |
user, mmpData |
getExpectMmpData(user, mmpData) |
这样,我们产出结果的预期数据有了,终的比对形式应该是这样子,resultMap为接口返回实际结果:
public void verify(String nick, String wwLimitData,
String punishData, String mmpData, Map<String, String> resultMap){
BaseUserDO expectUser= getExpectUser(nick);
String expectRuleCode= getExpectRuleCode(expectUser, wwLimitData);
boolean expectIsFrozen= getExpectIsFrozen(expectUser, wwLimitData);
String expectSuspended= getExpectSuspended(expectUser, expectIsFrozen);
String expectPunishData= getExpectPunishData(expectUser, punishData, expectSuspended);
String expectMmpData= getExpectMmpData(expectUser, mmpData);
Assert.assertEquals("user", expectUser, resultMap.get("user"));
Assert.assertEquals("ruleCode", expectRuleCode, resultMap.get("ruleCode"));
Assert.assertEquals("suspended", expectSuspended, resultMap.get("suspended"));
Assert.assertEquals("punishData", expectPunishData, resultMap.get("punishData"));
Assert.assertEquals("mmpData", expectMmpData, resultMap.get("mmpData"));
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11