jmeter4.0 统计结果次数 BeanShell Sampler,Debug Sampler

jmeter4.0 统计结果次数 BeanShell Sampler,Debug Sampler

业务场景:
抽奖活动,程序按比例分配奖品,测试员想模拟100次抽奖,获取抽奖的结果,分析大致的概率

1.setUp Thread Group 前置,右击添加 BeanShell Sampler
输入

props.put("a",0);
props.put("b",0);
props.put("c",0);
props.put("d",0);
props.put("e",0);
props.put("f",0);
props.put("g",0);

这边犹如一个map 存放键值对
这段一定要前置,否则每次运行都会将value回0
2.添加线程组-》添加http请求
http请求下添加JSON Extractor(因为我们需要从接口返回的json中获取信息进行统计)
下列是我的接口返回回来的json数据
{"code":200,"msg":"0.3%加息劵","weight":1}

JSON Extractor中设置
JSONPath Expression: $.msg
names of created variables:messageYyq
3.添加BeanShell Sampler
此BeanShell Sampler事在线程组下的 会被多次执行
代码如下:


String value = vars.get("messageYyq");

if("飞科剃须刀".equals(value)){
    int x = props.get("a")+1;
    props.put("a",x);
    }
if("赤霞珠干红酒".equals(value)){
    int x = props.get("b")+1;
    props.put("b",x);
    }
if("亚麻籽油".equals(value)){
    int x = props.get("e")+1;
    props.put("e",x);
    }
if("30元返现劵".equals(value)){
    int x = props.get("f")+1;
    props.put("f",x);
    }
if("50元京东E卡".equals(value)){
    int x = props.get("g")+1;
    props.put("g",x);
    }
if("0.3%加息劵".equals(value)){
    int x = props.get("d")+1;
    props.put("d",x);
    }
if("1%加息劵".equals(value)){
    int x = props.get("c")+1;
    props.put("c",x);
    }

4.添加Debug Sampler,将jmeter properties 设置为true

最后Debug Sampler运行 结果如下:
    START.YMD=20180612
TESTSTART.MS=1528853588059
a=0
b=0
beanshell.server.file=../extras/startup.bsh
c=0
classfinder.functions.contain=.functions.
classfinder.functions.notContain=.gui.
cookies=cookies
cssParser.className=org.apache.jmeter.protocol.http.parser.CssParser
cssParser.types=text/css
csvdataset.file.encoding_list=UTF-8|UTF-16|ISO-8859-15|US-ASCII
d=20
e=0
f=0
g=0

可以看出 变量次数都有输出

猜你喜欢

转载自blog.51cto.com/13788390/2128725