当前位置:网站首页>Jmeter自带函数不够用?不如自己动手开发一个
Jmeter自带函数不够用?不如自己动手开发一个
2022-07-07 01:11:00 【码同学软件测试】
在Jmeter的函数助手里,有很多内置的函数,比如Random、UUID、time等等。使用这些函数可以快速帮我们生成某些数据,进行一些逻辑处理。用起来非常的方便。
但是在实际接口测试过程中,有很多的需求,Jmeter内置的函数可能并不能满足我们的需求。这个时候我们可以通过自己编写代码,扩展Jmeter的内置函数。
比如现在想在Jmeter里添加一个简单的求和的函数,代码逻辑非常简单,大体代码如下:
public int sum(int a, int b){
return a + b;
}
接下来来看下如何把自定义的逻辑封装为Jmeter的内置函数。
新建工程
在idea中新建Java工程,然后把Jmeter的核心jar包ApacheJMeter_core.jar(在jmeter的lib/ext目录下可以找到)导入到工程中
在src目录下新建package,需要注意的是package的名字必须包含".functions",比如"com.mtx.jmeter.functions",JMeter设计让一些核心的类可以在非UI的方式下运行的时候能被加载进来,这些类会被优先加载。加载这些类的时候是通过命名规则来实现的。所有实现function的类必需包含".functions",否则自定义的函数不会生效。
创建自定义函数类
新建一个类,继承Jmeter的抽象类AbstractFunction。在函数类里,需要定义以下属性和方法。
属性
自定义函数的参数名称列表,List类型
自定义函数的名称,String类型
保存用户输入数据的数组,CompoundVariable[]类型
方法
execute:执行函数的逻辑
setParameters:获取用户输入的参数
getReferenceKey:返回自定义函数的名称
getArgumentDesc:返回自定义函数所有的参数名描述
具体代码如下:
将代码导出为jar包
在idea中设置工程的归档品artifacts,然后通过build,将代码导出为jar包,然后放到Jmeter的lib/ext目录下,再启动Jmeter。
函数助手中可以看到刚才的函数名称和参数。
输入参数,运行函数,就可以看到计算结果。
边栏推荐
- [shell] clean up nohup Out file
- Interview skills of software testing
- Peripheral driver library development notes 43: GPIO simulation SPI driver
- 解决pod install报错:ffi is an incompatible architecture
- 数字IC面试总结(大厂面试经验分享)
- [FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
- SAP ABAP BDC (batch data communication) -018
- Change the original style of UI components
- linear regression
- 苹果cms V10模板/MXone Pro自适应影视电影网站模板
猜你喜欢
jvm命令之 jcmd:多功能命令行
JVM命令之 jinfo:实时查看和修改JVM配置参数
Introduction to the extension implementation of SAP Spartacus checkout process
如何在Touch Designer 2022版中设置解决Leap Motion不识别的问题?
Check point: the core element for enterprises to deploy zero trust network (ztna)
cf:C. Column Swapping【排序 + 模拟】
404 not found service cannot be reached in SAP WebService test
JVM命令之 jstat:查看JVM統計信息
OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
How to improve website weight
随机推荐
PTA TIANTI game exercise set l2-003 moon cake test point 2, test point 3 Analysis
On the discrimination of "fake death" state of STC single chip microcomputer
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
@pathvariable 和 @Requestparam的详细区别
Classic questions about data storage
MySQL performance_ Schema common performance diagnosis query
Question 102: sequence traversal of binary tree
jvm命令之 jcmd:多功能命令行
成为资深IC设计工程师的十个阶段,现在的你在哪个阶段 ?
Financial risk control practice - decision tree rule mining template
每秒10W次分词搜索,产品经理又提了一个需求!!!(收藏)
PTA 天梯赛练习题集 L2-003 月饼 测试点2,测试点3分析
zabbix_ Get test database failed
Reading notes of Clickhouse principle analysis and Application Practice (6)
Personal imitation SSM framework
[FPGA tutorial case 14] design and implementation of FIR filter based on vivado core
原生小程序 之 input切换 text与password类型
Mysql-centos7 install MySQL through yum
ML's shap: Based on the adult census income binary prediction data set (whether the predicted annual income exceeds 50K), use the shap decision diagram combined with the lightgbm model to realize the
MFC BMP sets the resolution of bitmap, DPI is 600 points, and gdiplus generates labels