当前位置:网站首页>Function secondary development / plug-in development of JMeter (detailed version)
Function secondary development / plug-in development of JMeter (detailed version)
2022-07-23 17:05:00 【The test is super standard】
Don't go , The whole network should not explain so carefully , Give me a compliment after reading it ~
JMeter Secondary development of functions in ? What's the idea ?
1、JMeter It provides an interface for users to carry out secondary development , The interface can be introduced ApacheJMeter_components.jar、ApacheJMeter_core.jar Two packages get .( Maybe you see what others want to introduce jar There will be more bags , In fact, normal development is just these two , So at least these two bags are enough )
2、 The developed code needs to conform to JMeter The specification of : First of all , The new package name must be in functions ending ; second , Method classes need to inherit AbstractFunction class , and AbstractFunction There are four functions to be implemented in the class , Among them, the functions we want to realize need to be realized by combining these four functions .
Now let's start ~
Environmental preparation
First of all 、 Add dependency package :
Two jar Wrapped in JMeter Install under directory \lib\ext Folder , Build a new one in the project lib Catalog , hold jar Put the bag in , Then add it to the project (IDEA Add dependencies to the project jar package -CSDN Blog ):
ApacheJMeter_components.jar
ApacheJMeter_core.jar
second , Create packages with functions ending , Class inheritance created at the same time AbstractFunction class , When we inherit , If you find out, you will report an error , According to the prompt , The import method :

AbstractFunction A simple description of the four methods of class
Function overview :
package com.functions;
import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.functions.AbstractFunction;
import org.apache.jmeter.functions.InvalidVariableException;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
import java.util.Collection;
import java.util.List;
public class test extends AbstractFunction {
@Override
public String execute(SampleResult sampleResult, Sampler sampler) throws InvalidVariableException {
// The executing body of the function , Function logic processing , The final processing returns the result
return null;
}
@Override
public void setParameters(Collection<CompoundVariable> collection) throws InvalidVariableException {
// For reception 、 Handle the parameter value entered by the user when calling the function
}
@Override
public String getReferenceKey() {
// Name of function , And the function name called when referencing
return null;
}
@Override
public List<String> getArgumentDesc() {
// Custom function parameter list
return null;
}
}Case study
function : By input Area code 、 Date of birth 、 Gender , Generate a virtual ID number
Result display :

Overall code example :
package com.functions;
import com.IdNumTool;
import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.functions.AbstractFunction;
import org.apache.jmeter.functions.InvalidVariableException;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public class CardToolFunctions extends AbstractFunction {
public String card_code = "";
public String card_birthday = "";
public String card_sex = "";
// Define function parameter list
@Override
public List<String> getArgumentDesc() {
List<String> parms = new LinkedList<String>();
parms.add(" Please enter the area code ( Example :430922)");
parms.add(" Please input birthday ( Format :xxxx-xx-xx)");
parms.add(" Please enter gender ( male :1, Woman :2)");
return parms;
}
// For reception 、 Handle the parameter value passed in when the user calls the function
@Override
public void setParameters(Collection<CompoundVariable> collection) throws InvalidVariableException {
//collection by getArgumentDesc The value entered by the user received by the function
// Check whether the parameter value entered by the user is equal to 3 individual
checkParameterCount(collection,3);
// hold Collection<CompoundVariable> Convert to array , Fixed writing
Object[] parmsData = collection.toArray();
// hold data Object values do CompoundVariable Cast of type , Reuse execute Convert value to String type
card_code = ((CompoundVariable)parmsData[0]).execute();
card_birthday = ((CompoundVariable)parmsData[1]).execute();
card_sex = ((CompoundVariable)parmsData[2]).execute();
}
// The executing body of the function , Execute specific business logic 、 function
@Override
public String execute(SampleResult sampleResult, Sampler sampler) throws InvalidVariableException {
// initialization idNumTool class
IdNumTool idNumTool = new IdNumTool();
String idcard = idNumTool.getidcard(card_code,card_birthday,card_sex);
return idcard; // Return the ID number to the user
}
// The name of the function to call
@Override
public String getReferenceKey() {
String key = "__idCard";
return key ;
}
}Next, let's talk about each function
getReferenceKey function
Relatively simple , Is to define the name of the function , The main thing to note is that it needs to start with two underscores , This is a JMmter According to the standard .
public String getReferenceKey() {
String key = "__idCard";
return key ;
}
getArgumentDesc function
Parameters to describe
public List<String> getArgumentDesc() {
List<String> parms = new LinkedList<String>();
parms.add(" Please enter the area code ( Example :430922)");
parms.add(" Please input birthday ( Format :xxxx-xx-xx)");
parms.add(" Please enter gender ( male :1, Woman :2)");
return parms;
}setParameters
Process the parameter values entered by the user
public void setParameters(Collection<CompoundVariable> collection) throws InvalidVariableException {
//collection by getArgumentDesc The value entered by the user received by the function
// Check whether the parameter value entered by the user is equal to 3 individual
checkParameterCount(collection,3);
// hold Collection<CompoundVariable> Convert to array , Fixed writing
Object[] parmsData = collection.toArray();
// hold data Object values do CompoundVariable Cast of type , Reuse execute Convert value to String type
card_code = ((CompoundVariable)parmsData[0]).execute();
card_birthday = ((CompoundVariable)parmsData[1]).execute();
card_sex = ((CompoundVariable)parmsData[2]).execute();
}
execute Method
Specific logic implementation , Result passed return return , The specific implementation here is through IdNumTool Class implementation , This is already encapsulated , Here is just a call ;
public String execute(SampleResult sampleResult, Sampler sampler) throws InvalidVariableException {
// initialization idNumTool class
IdNumTool idNumTool = new IdNumTool();
String idcard = idNumTool.getidcard(card_code,card_birthday,card_sex);
return idcard;
}export jar package
After the code is written , export jar package , Method JMeter Of lib\ext Under the table of contents , And then restart JMeter That's all right. ~
export jar The method of has been written before , Specific view :IDEA export jar Package to JMeter-CSDN Blog
Result display :

Conclusion
Because the production of ID cards is more sensitive , It's not public here jar Bag
Learning reference :Jmeter Detailed explanation of user-defined functions of secondary development _ Bili, Bili _bilibili
边栏推荐
- PMP practice once a day | don't get lost in the exam -7.23
- What are the principal guaranteed financial products with an annual interest rate of about 6%?
- Fundamentals of C language -- 2-6 pointers, arrays and sizeof operators
- 一道反序列化的CTF题分享
- TOPSIS法(MATLAB)
- 【Flutter -- 布局】弹性布局(Flex 和 Expanded)
- 软件测试计划包括哪些内容,测试计划如何编写。分享测试计划模板
- Case analysis of building campus information management system with low code
- [web vulnerability exploration] SQL injection vulnerability
- Weisfeiler-Lehman图同构测试及其他
猜你喜欢

Pinduoduo app product details interface to obtain activity_ ID value (pinduoduo activity_id interface)

简单了解首个 EVM 等效的 zkEVM Polygon 为何全力押注

VSCode PIO创建工程失败分析和解决办法

分类模型——逻辑回归、Fisher线性判别(SPSS)

软件测试计划包括哪些内容,测试计划如何编写。分享测试计划模板

Wechat applet wx.hideloading() will close the toast prompt box

Lake Shore - empx-h2 low temperature probe station

Compose canvas pie chart effect drawing

General paging function

The first stage of basic knowledge of numpy data analysis (numpy Foundation)
随机推荐
Summary of after class homework of Microcomputer Principle and technical interface
PIP reports an error could not find a version that satisfies the... No matching distribution
距离IoU损失:包围盒回归更快更好的学习(Distance-IoU Loss: Faster and Better Learning for Bounding Box Regression)
JS if the decimal is 0, subtract it, not keep it
iphone 无法打开openv**文件的解决方案
It's not safe to open an account at qiniu business school
Weisfeiler Lehman graph isomorphism test and others
Priyanka Sharma, general manager of CNCF Foundation: read CNCF operation mechanism
Tips and tricks for Neural Networks 深度学习训练神经网络的技巧总结(不定期更新)
Tips and tricks for neural networks deep learning and training skills summary (updated from time to time)
AXI interconnect IP核的说明及用法
系统内存介绍和内存管理
PWN entry (3) heap
opencv之打开摄像头、边缘检测
leetcode-168.Excel表列名称
IDEA中给项目添加依赖的jar包
VMware虚拟机的三种网络模式
Shell | ssh失败原因及解决方法不完全总结
[31. Maze walking (BFS)]
一文带你了解什么是TypeScript
