参数化有几种方式
主要有两部分组成,一部分是伪数据,另一部分是数据组合,运用一般是随机法
一、伪数据,主要用到两个,一个是自带的函数,另一个是第三方写好的生成器,第三方写好的工具可以用下面那个
https://github.com/yindz/common-random
例子如下
import com.apifan.common.random.constant.CreditCardType;
import com.apifan.common.random.source.PersonInfoSource;
//生成1个随机中文人名(性别随机)
String name = PersonInfoSource.getInstance().randomChineseName();
//生成1个随机的虚拟身份证号码,地区为广东省,男性,年龄为30岁
String redit = PersonInfoSource.getInstance().randomMaleIdCard("广东省", 30);
//生成1个随机中国大陆手机号
String telPhone = PersonInfoSource.getInstance().randomChineseMobile();
vars.put("name",name);
vars.put("redit",redit);
vars.put("telPhone",telPhone);
二、数据组合
应用场景是,可填可不填,可选可选,可输入可不输入,基本上用户自主行为,都要加这个空值判断
//第一步String into an ArrayList
List<String> List = new ArrayList<String>(Arrays.asList(vars.get("author_ALL").split(",")));
List.add("");
//传统for方法永远是历久弥新,经典好用(推荐)
for (int i = 0; i < List.size(); i++) {
log.info("for: "+List.get(i));
}
三、随机法
1、随机单选
int List_index = (int) (Math.random()*List.size());
log.info("随机单选"+List.get(List_index));
2、随机多选
Collections.shuffle(List);//洗牌
List List_multiple = (List.subList(0,List_index+1));//subList截取
log.info("随机多选List"+List_multiple);
//由于得到的还是list,最后一般还,vars.put("toString()",toString())相对应的格式,自己处理下就好了