Article Directory
foreword
Recently, the company's project needs to carry out stress testing to check whether the multi-tenant data in the SAAS system is serialized or not!
Pressure testing tool
I believe that JMeter is a tool that everyone who has been in contact with the test has heard of it. Even if it is developed, it should be understood more or less.
This is the protagonist of today. We use this tool to complete our stress testing of the system.
how to use
Next, let's take a look at how to use this pressure measurement tool
Start the JMeter tool
Open the JMeter package directory, enter the bin directory, and double-click the jmeter.bat file to open it.
After double-clicking, two interfaces will appear, one is the startup interface of cmd, as follows:
let’s translate the contents of the above window:
Do not use GUI mode for load testing! , for test creation and test debugging only.
For load testing, use CLI mode (formerly NON GUI):
jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]
and modify the environment variables of the JMeter batch file :HEAP="-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m"
Another post-start operation page is as follows:
Start creating a test environment
1. Create a thread group
Right-click on "Test Plan" [add] –> [Threads (Users)] –> [Thread Group]
to set the number of threads and the number of cycles. Here, the number of threads is set to 300, and the loop is performed 4 times.
2. Configuration components
Right-click [Add]–>[Config Element]–>[HTTP Request Default] on the Thread Group we just created to configure the program protocol, address, and port we need to test. If all interface test access domain names and If the ports are the same, you can use this component to configure. If the server address is changed, you only need to modify the default value of the request. The specific UI interface is shown in the following figure:
3. Construct HTTP request
Right-click on "Thread" [Add] -> [Samlper] -> [HTTP Request] the request path and data of the API to be tested. The specific operation UI interface is shown in the figure below
4. Add HTTP request header information
Right-click on the created Thread Group [Add]–>[Config Element]–>[HTTP Header Manage] to configure token and Content-Type here
5. Add assertions
Right click on the created Thread Group [Add] –> [Assertion] –> [Response Assertion]
Determine whether the request is successful or not based on the response data. I'm only judging here if the response code is 200. You can also configure prompt information
The specific UI is shown in the figure below:
6. Add view result tree
Right click on the created Thread Group [Add] –> [Listener] –> [View the Result Tree]
Then click the run button to see our result tree
7. Add aggregate report information
Right click on the created Thread [Add] –> [Linster] –> [Aggregate Report]
Then click the run button to see the results of the aggregation report
8. The test plan is created
The above steps are completed, we can save the test plan
Execute the test plan
It is best to use the GUI interface when executing the test plan, and you need to go to the command line to execute the test plan
The executed command is:
jmeter -n -t filename.jmx -l webreport/testResult.txt -e -o webreport/webs
filename.jmx is the test plan file path
webreport/testResult.txt is the test result file path
webreport/webs Save the path for the web report (remember to keep the folder empty)
Well, that's all about the use of JMeter.
Welcome everyone to click on the card below to pay attention to "coder trainees"