JMeter参化数

参数化有几种方式

主要有两部分组成,一部分是伪数据,另一部分是数据组合,运用一般是随机

一、伪数据,主要用到两个,一个自带函数,另一个是第三方写好的生成器,第三方写好的工具可以用下面那个

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())相对应的格式,自己处理下就好了

相关文章

Jmeter:Authenticationcredentialswerenotprovided上次在使...
初次使用jmeter时,结果树中返回的数据为未转码内容,如下:...
jmeter默认语言设置: 1、临时设置:进入options--ChooseLa...
第一步:打开jmeter工具。 第二步:点击鼠标右击,点击添加...
在之前的博文中,Jmeter二次开发——基于Java请求,已介绍了...
打开虚拟机然后用远程连接工具SSH连接到数据库将serveragent...