博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jmeter4.0 统计结果次数 BeanShell Sampler,Debug Sampler
阅读量:7060 次
发布时间:2019-06-28

本文共 1843 字,大约阅读时间需要 6 分钟。

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=20180612TESTSTART.MS=1528853588059a=0b=0beanshell.server.file=../extras/startup.bshc=0classfinder.functions.contain=.functions.classfinder.functions.notContain=.gui.cookies=cookiescssParser.className=org.apache.jmeter.protocol.http.parser.CssParsercssParser.types=text/csscsvdataset.file.encoding_list=UTF-8|UTF-16|ISO-8859-15|US-ASCIId=20e=0f=0g=0

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


当然也可以不用Debug Sampler

在第二个BeanShell Sampler代码最后加上

String cc = "a:"+props.get("a")+"d:"+props.get("d");    return cc;

这样在 结果树中的BeanShell Sampler里的响应数据里 也能看到 更为清晰 。

转载于:https://blog.51cto.com/13788390/2128725

你可能感兴趣的文章
Git 安装与简单使用(新手必看)
查看>>
leetcode-143. Reorder List
查看>>
怎样解决if __name__ == "__main__":下面的代码没有执行的问题
查看>>
python从入门到实践-6章字典
查看>>
glusterfs 步骤
查看>>
浅谈gibbs sampling(LDA实验)
查看>>
Asp.net 后台添加CSS、JS、Meta标签
查看>>
JDBC连接SQL Server2008基本格式及示例代码 (转载收藏~)
查看>>
以前的GHOST系统没落,现在 原版WINDOWS更新节奏还快 MSDN itellyou
查看>>
scala学习手记21 - 传递变长参数
查看>>
一些JavaScript中的DOM的优化小技巧
查看>>
用PrintStream向文件输入内容
查看>>
412. Fizz Buzz
查看>>
Uva 10879 - Code Refactoring
查看>>
控制总线上发送的控制信息
查看>>
c#解析xml
查看>>
每日一句(15)
查看>>
读书笔记--SQL必知必会--建立练习环境
查看>>
捕获、冒泡
查看>>
C# 递归获取 文件夹的 所有文件
查看>>