Getting started with JMeter performance testing
JMeter is an excellent open-source testing tool, is each senior test engineer, must master the test tools, skilled use of jmeter can greatly improve work efficiency.
Skilled use of jmeter, can use JMeter to fix things, you will not use LoadRunner.
The "Small tank JMeter Tutorial" will cover the various functions of jmeter and will allow readers to quickly master the various uses of JMeter through a rich set of examples.
This article will explain the basic usage of jmeter through a practical test example. The script for this article is provided at the end of this article. Students who do not like reading articles can read the script directly.
Read Catalogue
- JMeter Introduction
- How to learn JMeter well
- JMeter Download and run
- Examples of actual tests
- First step: New Thread Group
- Step Two: Create a new HTTP Request
- Step three: Create a new HTTP Header Manager
- Fourth step: Create a new View Results Tree
- Fifth step: Run the test to see the results
- Sixth step: Add assertion and assertion Results
- Seventh step: Using user-defined variables
- Eighth Step: Association
- Source code Download
Jmeter Introduction
Jmeter is a Java-developed, open source, free, test tool used primarily for functional testing and performance testing (stress testing/load testing).
and using JMeter to test the Restful API is very useful.
How to learn JMeter well
If you use JMeter to perform functional testing on the Web, or performance testing. You must be proficient in the HTTP protocol to learn jmeter well. Otherwise it's hard to understand the concept of jmeter.
If you are unfamiliar with the HTTP protocol, you can refer to my "Small tank: HTTP protocol Tutorial"
Jmeter Download and run
Official website: http://jmeter.apache.org/
After decompression, run "Bin/jmeter.bat"
Jmeter is supported in Chinese, after starting Jmeter, click Options, Choose Language to select the language
Examples of actual tests
Goal: Get weather data for the city:
First step: Send request to get city code
Http://toy1.weather.com.cn/search?cityname= Shanghai
Get the city code of Shanghai from the response of this request. Like what:
The area code for Shanghai is 101020100.
The area code for Shanghai Zoo is: 10102010016A
Step two: Send request to: http://www.weather.com.cn/weather2d/101020100.html can get weather data for the city
First step: Create a new thread Group
You must create a new thread group, all tasks for jmeter must be handled by the thread, and all tasks must be created below the thread group.
Step Two: Create a new HTTP Request
For example, I want to send an HTTP request for a GET method: Http://toy1.weather.com.cn/search?cityname= Shanghai
You can fill in this
The third step is to add the HTTP Head Manager
Select the new HTTP request that you created in the previous step. Right-click to create a new HTTP Header manager. Add a header
Fourth step: Add View Results Tree
View Results Tree is used to see the results of the run
Fifth step: Run the test to see the results
to here. We've managed to get it running.
Sixth step: Add assertion and Assert Results
Select HTTP Request, right-add-> assertions, Response assertion. Add Patterns to Test
Then add a assetion Results to see the results of the assertion execution.
Check the thread Group right-click Add-Listener-assertion Results.
After running, if the HTTP response does not contain the expected string. Then test will fail.
7th step: Using user-defined variables
We can also define variables in JMeter. For example, I define a variable called City. Use it when using ${city}
Add a User Defined Variables. Check the thread Group: Right-click Add, Config Element, User Defined Variables.
We add a variable: City
Then use this variable in the HTTP request
Eighth Step: Association
The so-called Association is the second requst, using the data from the first request
We need to create a new regular expression in the first HTTP requst, extract the value of the response into the variable and provide it to other HTTP request
Select the first HTTP Request, right-click Add, Post processors, Regular expresstion Extractor
Now create a second HTTP Request, send to: http://www.weather.com.cn/weather2d/${citycode}.html
The data in ${citycode} is taken from the regular Expression Extractor
Here, the script is all written, run, and look at the final result.
Getting started with JMeter performance testing