JMeter is an open source testing tool of the Apache organization, which can be used for protocol-based function and performance testing.
Nowadays, front-end and back-end separation and microservice architecture are becoming more and more popular, and more and more business processing logic has been "exposed" at the interface level. In addition, API interfaces usually need to be forward compatible, causing a lot of regression testing workload, which brings more interface testing requirements.
In this article, we introduce how to use JMeter to do HTTP interface testing.
JMeter installation
- Download the latest version of JMeter from here , and unzip it to a local directory;
- Double-click the jmeter.bat bin directory to start JMeter. For non-Windows systems, please use the jmeter file;
Select Menu Options-> the Choose Language-> Chinese (Simplified) , switch to Chinese; want to permanently modify the language, edit bin directory jmeter.properties file;
#language=en language=zh_CN
To prevent garbled characters, please modify the character set to UTF-8, and add the following line jmeter.properties
#sampleresult.default.encoding=ISO-8859-1 sampleresult.default.encoding=UTF-8
Quick start
- TestPlan in the tree structure on the left, select Add -> Thread (User) -> Thread Group to enter the thread group setting page;
error handling: determines the action to be executed after an error occurs, such as continue or stop.
threads: concurrent virtual users.
Ramp-Up time (seconds): starts all threads elapsed time, the configuration in the figure will start 2 (10/5) threads per second.
cycle times: The repeated executions of 1617f351743c1b. The configuration in the figure will send 30 (10x3) requests. Check forever and will keep sending requests.
delays the creation of threads until needed: controls the creation time of threads. By default, unchecked means that all threads are initially created. Note that the thread creates the difference between starting in Ramp-Up.
Scheduler
Duration: control operation, and it will be forcibly terminated when the time cycle is not over.
start delay: adds a delay between the start of the test and the start of execution. - Right-click the newly created thread group, select the menu Add -> Sampler -> HTTP Request , and do the following configuration on the opened page;
Protocol: http
server name: www.baidu.com
port: remains empty as the default value of 80;
request type: select GET
parameters: add query parameters, the key is "wd" and the value is "Zen Tao". - Right-click the thread group, select the menu listener -> view result tree , enter the request result viewer page;
- Click the save and execute buttons in the toolbar in turn to test run the HTTP request we configured;
- In the request result viewer, select an HTTP request, and you can view its status, request and response content on the right.
- Right-click the thread group, select the menu >Assertion->HTML Assertion , and do the following configuration on the opened page;
test field: response text
test mode: Apache JMeter - Click the save and execute buttons in the toolbar in turn to execute the interface test;
- In the result viewer, select the last HTTP request to confirm the success of the execution and assertion.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。