JMeter interface test script writing

1. Introduction and importance of interface testing

Interface testing is a type of testing that tests the interfaces between system components. Interface testing is mainly used to detect the interaction points between external systems and internal subsystems. The focus of the test is to check the exchange of data, the process of delivery and control management, and the mutual logical dependencies between the systems.

The core of interface testing is to ensure the correctness and stability of the system, and its importance is mainly as follows:

1. Bugs can be found early, which is in line with the concept of quality control forward.

2. Interface testing is cost-effective, because interface testing can be automated and continuous integration.

3. The interface test conducts a comprehensive test on the system interface from the user's point of view. In actual projects, interface testing will cover a certain degree of business logic

2. General steps of JMeter for http interface testing

The main steps mainly include:

1. Thread group

2. HTTP header manager

3. HTTP request (protocol, IP, port number, request method, path, content encoding, request parameters, etc.)

4. Parameterization (csv data set config, user-defined variables, etc.)

5. Response assertion

6. View the result tree

For different interface services, other component configurations are sometimes added. The following creates an interface test script according to the actual scenario

3. Practical process

1. Add a thread group, use the default value

2. Add http request

1) Parameter configuration

 3. Add a response assertion (according to the return value of the interface, add the assertion statement)

1) Assertion configuration, fill in the assertion statement

4. Add HTTP header manager

 1) The configuration is as follows:

5. Add view result tree

6. Run, view the results, and show that the operation is successful

7. Parameterized configuration (in actual scenarios, some interface request parameters are not static, and different parameters need to be selected according to specific services, or concurrent execution scenarios, etc.), use csv set data config

1) The configuration is as follows, fill in the file path (local file save path), file encoding, variable name, and keep the rest of the parameters at their default values

2) Modify the corresponding parameters in the sampler at the same time, and modify the format to ${parameter}

3) Modify the number of threads in the thread group

8. Add http request default value

1) Configure the default parameters of the interface request. After the configuration is complete, there is no need to configure these values ​​again in the subsequent http request interface

2) The http request is as follows:

9. Extract the token value of the login interface

1) Check the return value of the login interface, there is "access_token" in the returned data:

2) Add a regex extractor after the http request

3) Fill in the expression configuration

4) The token value configuration is added to the http information header manager, and the token value of the subsequent interface request is taken from the value obtained in the request interface

5) In the same steps, add other http requests, so I won’t go into details here

6) Run, view the running results

Guess you like

Origin blog.csdn.net/weixin_45189665/article/details/125261566