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

  1. Download the latest version of JMeter from here , and unzip it to a local directory;
  2. Double-click the jmeter.bat bin directory to start JMeter. For non-Windows systems, please use the jmeter file;
  3. 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
  4. 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

  1. TestPlan in the tree structure on the left, select Add -> Thread (User) -> Thread Group to enter the thread group setting page;
    image.png
    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.
  2. Right-click the newly created thread group, select the menu Add -> Sampler -> HTTP Request , and do the following configuration on the opened page;
    image.png
    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".
  3. Right-click the thread group, select the menu listener -> view result tree , enter the request result viewer page;
  4. Click the save and execute buttons in the toolbar in turn to test run the HTTP request we configured;
  5. In the request result viewer, select an HTTP request, and you can view its status, request and response content on the right.
    image.png
  6. Right-click the thread group, select the menu >Assertion->HTML Assertion , and do the following configuration on the opened page;
    image.png
    test field: response text
    test mode: Apache JMeter
  7. Click the save and execute buttons in the toolbar in turn to execute the interface test;
  8. In the result viewer, select the last HTTP request to confirm the success of the execution and assertion.
    image.png

Thematic catalog


陈哥聊测试
158 声望3.3k 粉丝

资深敏捷测试顾问,国内知名项目管理软件禅道团队成员。