当前位置:网站首页>Interface test for quick start of JMeter
Interface test for quick start of JMeter
2022-07-26 16:12:00 【wangmcn】
Jmeter Quick interface test
Catalog
- 1、 Preface
- 2、 brief introduction
- 3、 install
- 4、 environment variable
- 4.1、Windows Environmental Science
- 4.2、Mac Environmental Science
- 5、 Start the program
- 6、 Directory description
- 7、 The operation sample
- 7.1、Get request
- 7.2、Post request
- 7.3、 Rely on requests
1、 Preface
Pressure measuring tool Jmeter In addition to performance testing , You can also do interface testing . When interface testing tends to be automated , You can use a typical interface automation test framework Jmeter + Ant + Jenkins.
This article will explain how to quickly use Jmeter To test the interface .
2、 brief introduction
Jmeter yes Apache Organization development based on Java Pressure testing tools for . For stress testing software , It was originally designed for Web Application testing , But then it expanded to other areas of testing .
It can be used to test static and dynamic resources , For example, static files 、Java Little service program 、CGI Script 、Java object 、 database 、FTP Servers and so on .
Jmeter Can be used for server 、 Network or object simulating huge load , Test their strength and analyze their overall performance from different stress categories . in addition ,Jmeter Ability to function on Applications / regression testing , Verify that your program returns what you expect by creating a script with assertions . For maximum flexibility ,Jmeter Allow regular expressions to create assertions .
Official website address :
https://jmeter.apache.org/
3、 install
Official website download address :
https://jmeter.apache.org/download_jmeter.cgi
Download the unzipped package version .
Be careful : need Java 8+ (JDK 1.8+) The above support .
About JDK Installation and configuration , Clickable Java- install Read the article .
For example, this explanation system brings JDK Version is 1.8.0_261.
For example, download apache-jmeter-5.4.1.zip
When the download is complete , Unzip it to the path you specify .
for example :
Windows System , Unzip to C Under the root directory .
Path is C:\apache-jmeter-5.4.1
Mac System , Unzip to /Users/wangmeng Under the table of contents .
Path is /Users/wangmeng/apache-jmeter-5.4.1
4、 environment variable
4.1、Windows Environmental Science
【 My computer 】 Right click ---> attribute ---> Advanced system setup ---> environment variable ---> System variables
newly build JMETER_HOME The value is C:\apache-jmeter-5.4.1
edit CLASSPATH The variable of ( If not, new ), The value is
%JMETER_HOME%\lib\ext\ApacheJMeter_core.jar;%JMETER_HOME%\lib\jorphan.jar
edit PATH The new value added is %JMETER_HOME%\bin
After the save , Open the command line as Administrator , Input jmeter -v
Environment variable configuration succeeded
4.2、Mac Environmental Science
Open the terminal , edit .bash_profile file .
vim .bash_profileAdd the following configuration :
export JMETER_HOME=/Users/wangmeng/apache-jmeter-5.4.1
export PATH=${PATH}:$JMETER_HOME/bin
export CLASSPATH=:$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorphan.jarSave and exit , send .bash_profile The contents of the document take effect .
source ~/.bash_profileReopen the terminal , Input jmeter -v
Environment variable configuration succeeded
5、 Start the program
1、 Open command line or terminal input jmeter, You can start the program ( If the environment variable has been configured successfully ).
2、 Or open Jmeter\bin Directory to start the application .
Windows System , double-click jmeter.bat that will do .
Mac System , double-click jmeter that will do .
6、 Directory description
- backups: Backup directory , Is to put your own jmx Script for backup , Each save will save the script to this directory , Saving multiple times will save multiple identical files , The file name is incremented by default .
- bin: Include startup 、 Configuration and other related commands .
- bin\jmeter.properties: Core profile , Various configurations are basically completed here .
- docs: Official interface document .
- extras: Auxiliary Library .
- lib: Store all kinds of Jmeter The source code of the core library jar package , Store your own secondary development jar package .
- lib\ext: Official third-party plug-ins .
- LICENSE: License description .
- licenses: License, etc .
- NOTICE: A simple message says .
- printable_docs: Offline help documentation , You can view functions and other contents .
- README.md: Official basic introduction .
7、 The operation sample
This article simulates the use of interface request links moco Generate .
About moco Deployment and use of , Clickable moco Series of chapters .
1、 Add thread group
【 test plan 】 Right click ---> Add ---> Threads(Users) ---> Thread Group
2、 Set the number of threads ( Number of concurrent users ) And the number of cycles
This chapter explains interface testing , Simulate one user request at a time , Therefore, the number of users and the number of cycles are 1 that will do .
7.1、Get request
Interface request address :http://localhost:8083/getdemo
As shown in the figure : First use Postman, Access this interface .
GET request ,2 Parameters username、password
The returned data is “ Successful operation ”
1、 add to HTTP request
【 Thread group 】 Right click ---> Add ---> Sampler ---> HTTP Request
Fill in the relevant configuration information .
Mode one :
- The name of the interface :demo01
- agreement :http
- Server name or IP:localhost
- Port number :8083
- Method :GET
- route :/getdemo
- Content encoding :utf-8
- Parameters: Fill in the corresponding parameter name and parameter value
Mode two :
- The name of the interface :demo01
- agreement :http
- Server name or IP:localhost
- Port number :8083
- Method :GET
- route :/getdemo?username=admin&password=123456
- Content encoding :utf-8
2、 Add response assertion
【demo01】 Right click ---> Add ---> Assertions ---> Response Assertion
Enter what the assertion matches .
According to the example interface , If the returned text content is equal to “ Successful operation ”, Then it's even Pass
3、 Add assertion results
【demo01】 Right click ---> Add ---> Listener ---> Assertion Results
4、 Add view result tree
【demo01】 Right click ---> Add ---> Listener ---> View Results Tree
5、 Run script
Operation mode 1 :【 Thread group 】 Right click ---> Start
Operation mode II : Click the run button .
6、 Running results
Look at the assertion results , Verification passed ,Pass
View the result tree , You can view request and response data , Verification passed ,Pass
7.2、Post request
Interface request address :http://localhost:8083/postdemo
As shown in the figure : First use Postman, Access this interface .
POST request ,2 Parameters username、password
The returned data is “ Successful operation ”
1、 add to HTTP request
【 Thread group 】 Right click ---> Add ---> Sampler ---> HTTP Request
Fill in the relevant configuration information .
- The name of the interface :demo02
- agreement :http
- Server name or IP:localhost
- Port number :8083
- Method :POST
- route :/postdemo
- Content encoding :utf-8
- Parameters: Fill in the corresponding parameter name and parameter value
2、 Add response assertion
【demo02】 Right click ---> Add ---> Assertions ---> Response Assertion
Enter what the assertion matches .
According to the example interface , If the returned text content is equal to “ Successful operation ”, Then it's even Pass
3、 Add assertion results
【demo02】 Right click ---> Add ---> Listener ---> Assertion Results
4、 Add view result tree
【demo02】 Right click ---> Add ---> Listener ---> View Results Tree
5、 Run script
Operation mode 1 :【 Thread group 】 Right click ---> Start
Operation mode II : Click the run button .
6、 Running results
Look at the assertion results , Verification passed ,Pass
View the result tree , You can view request and response data , Verification passed ,Pass
7.3、 Rely on requests
There are two interfaces , Interface 1 There is an interface in the data returned after execution 2 Required request parameters , Then execute the interface 2 when , First execute the interface 1 Get the specified data returned .
Interface 1 Request address :http://localhost:8083/demo?aaa=123&bbb=456&ccc=789
As shown in the figure : First use Postman, Access this interface .
GET request ,3 Parameters aaa、bbb、ccc
return json The data is :
{
"mystatus": " Successful operation ",
"mytoken": "eyJhbGciOiJIUzI1NiJ9"
}
Interface 2 Request address :http://localhost:8083/demo2
As shown in the figure : First use Postman, Access this interface .
POST request , Request header has 2 Parameters Content-Type、mytoken
return json The data is :
{
"mystatus": " Successful operation ",
"mystatusid": "1"
}
Sent json strand .
1、 Add user parameters
Interface 1 And interface 2 They all have parameters ccc, And it's worth it 789, It can be set as a public user variable , Convenient and unified extraction .
【 Thread group 】 Right click ---> Add ---> Pre Processors ---> User Parameters
Fill in the parameters ccc And parameter values 789
2、 add to HTTP request ( Interface 1)
【 Thread group 】 Right click ---> Add ---> Sampler ---> HTTP Request
Fill in the relevant configuration information .
- The name of the interface :demo03-1
- agreement :http
- Server name or IP:localhost
- Port number :8083
- Method :GET
- route :/demo
- Content encoding :utf-8
- Parameters: Fill in the corresponding parameter name and parameter value ,${ccc} Reference user parameters for ccc Value .
(1) Add response assertion
【demo03-1】 Right click ---> Add ---> Assertions ---> Response Assertion
Enter what the assertion matches .
According to the example interface 1, If the returned text content includes the specified “ Successful operation ”, Then it's even Pass
(2) Add assertion results
【demo03-1】 Right click ---> Add ---> Listener ---> Assertion Results
(3) Add view result tree
【demo03-1】 Right click ---> Add ---> Listener ---> View Results Tree
(4) Add regular expression extractor
Used to extract interface 1 Returns the specified data , Interface 2 This data will be called .
【demo03-1】 Right click ---> Add ---> Post Processors ---> Regular Expression Extractor
Fill in the relevant regular expression information .
- Quote name : Variable name when referenced elsewhere , This is defined as my_token, Reference method :${ Quote name }
- Regular expressions : Data extractor ,() In parentheses is the value to be obtained ."mytoken":"( amount to LR The left border , )" amount to LR The right border of . And in parentheses .*? For regular expressions ,"mytoken":"(.*?)" Match the shortest , With "mytoken":" Start , With " Ending string .
- Templates : Template for creating strings from found matches . This is an arbitrary string with special elements , Used to reference a group in a regular expression . The syntax of the reference group is :1 Reference group 1,2 Reference group 2, wait .0 Reference the matching content of the whole expression .
- Match the Numbers : All the results of regular expression matching data can be regarded as an array , A matching number is the number one element of an array .-1 All ,0 Random ,1 first ,2 the second , And so on . If you just get the first value of the match , Then fill in 1
- The default value : Default value when matching fails .
(5) Add post debug processor
It is convenient to check whether the required information is correctly extracted in real time when debugging the script .
【demo03-1】 Right click ---> Add ---> Post Processors ---> Debug PostProcessor
3、 add to HTTP Head manager ( Interface 2)
Interface 2 There is request header information to be set , So add HTTP Head manager .
【 Thread group 】 Right click ---> Add ---> Config Element ---> HTTP Header Manager
Fill in the relevant configuration information .
${my_token} To reference regular expressions my_token Extract interface 1 Returns the specified value .
4、 add to HTTP request ( Interface 2)
【 Thread group 】 Right click ---> Add ---> Sampler ---> HTTP Request
Fill in the relevant configuration information .
- The name of the interface :demo03-2
- agreement :http
- Server name or IP:localhost
- Port number :8083
- Method :POST
- route :/demo2
- Content encoding :utf-8
- Body Data: Fill in the corresponding key value ,${ccc} Reference user parameters for ccc Value .
{
"id":"1",
"username":"test",
"password":"123456",
"ccc":"${ccc}"
}
(1) Add response assertion
【demo03-2】 Right click ---> Add ---> Assertions ---> Response Assertion
Enter what the assertion matches .
According to the example interface 2, If the returned text content includes the specified “ Successful operation ”, Then it's even Pass
(2) Add assertion results
【demo03-2】 Right click ---> Add ---> Listener ---> Assertion Results
(3) Add view result tree
【demo03-2】 Right click ---> Add ---> Listener ---> View Results Tree
5、 Run script
Operation mode 1 :【 Thread group 】 Right click ---> Start
Operation mode II : Click the run button .
6、 Running results
Interface 1, Look at the assertion results , Verification passed ,Pass
Interface 1, View the result tree , You can view request and response data , Verification passed ,Pass
Interface 1, View the result tree , Interface extracted by regular expression 1 Data returned by
Interface 2, Look at the assertion results , Verification passed ,Pass
Interface 2, View the result tree , You can view request and response data , Verification passed ,Pass
边栏推荐
- 6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
- 初识OpenGL (2)编译着色器
- Paper: all models are wrong, but many are useful: all models are wrong, but many are useful: understand the importance of variables by studying a whole class of prediction models at the same time
- Research and application of the whole configuration of large humanoid robot
- bucher齿轮泵QX81-400R301
- 辨析 Ruby 中的 Method 与 Proc
- 【ARM学习(9) arm 编译器了解学习(armcc/armclang)】
- 开发日常小结(11):文件上传功能改进:中文字符检测与文本内容处理
- Alibaba cloud DMS MySQL cloud database report error, solve!!
- First knowledge of OpenGL (3) fragment shader
猜你喜欢

PAT甲级 1050 String Subtraction

We were tossed all night by a Kong performance bug

Google Earth Engine——MERRA-2 M2T1NXSLV:1980-至今全球压力、温度、风等数据集

Understand │ XSS attack, SQL injection, CSRF attack, DDoS attack, DNS hijacking

【工具分享】自动生成文件目录结构工具mddir

【物理模拟】最简单的shape matching的原理与实践

A comprehensive review of image enhancement technology in deep learning

Google Earth engine - merra-2 m2t1nxlv: 1980 present global pressure, temperature, wind and other data sets

德国EMG易安基推动器ED301/6 HS

German EMG electric actuator eb800-60ii
随机推荐
2022 what is your sense of security? Volvo asked in the middle of the year
我们被一个 kong 的性能 bug 折腾了一个通宵
Development daily summary (11): file upload function improvement: Chinese character detection and text content processing
PAT甲级1048 Find Coins
[RCTF2015]EasySQL
Question collection come and ask nllb authors! (Zhiyuan live issue 24)
Musk was exposed to be the founder of Google: he broke up his best friend's second marriage and knelt down to beg for forgiveness
马斯克被曝绿了谷歌创始人:导致挚友二婚破裂,曾下跪求原谅
Pandora IOT development board learning (RT thread) - Experiment 17 esp8266 experiment (learning notes)
基于sisotool极点配置PI参数及基于Plecs的三相电压源逆变器仿真
A comprehensive review of image enhancement technology in deep learning
Botu PLC Sequential switch function block (SCL)
哪本书才是编程领域的“九阴真经”
Operating system migration practice: deploying MySQL database on openeuler
Internet Protocol
HaWe screw cartridge check valve RK4
Sword finger offer special assault edition day 11
Mapwithstate of spark streaming state flow
初识OpenGL (4)链接着色器
Jointly discuss the opening of public data, and the "digital document scheme" appeared at the digital China Construction Summit