JMeter Batch Interface Test

 

1. Background

Recently, I was preparing for an interface test in a middle station, and found that the number of interfaces is very large, 60 to 70, and each interface has a large number of parameters and various parameter verifications are required to test whether the interface can return the response value correctly. After thinking about several solutions, I decided to try to use JMeter's csv read to implement batch interface testing.

A complete set of practical tutorials on interface testing: The first recommendation of station B is worth your collection, from zero foundation to proficiency

2. Scripting

1. Add thread group

2. Add HTTP header manager

Add necessary interface information headers, such as Appid and Authorization

3. Add HTTP request

4. Add loop controller

5. Configure csv file

Define the incoming parameter name:

num: use case number

apiSeq: function serial number

apiName: interface function

classify: function module name

api: interface address

function: request method

parameter: request body parameter

expValue: expected result

Fill in the parameters according to the test case, as shown in the table below:

6. Add csv configuration file

Separate the variable names num, piSeq, apiName, classify, api, function, parameter, and expValue with English commas; because the first line of csv is the parameter name, in the parameter setting, ignore the first line and set it to True, and set the end-of-file character at the same time Stop the thread. Other parameters are shown in the figure below:

7. Set HTTP request parameters

The HTTP request name is set to: ${num}${apiSeq}${apiName};

The method is set to: ${function};

The path is set to: ${url};

The message body is set to: ${parameter}

8. Add assertions

Add a json assertion, return the result according to the http request, and compare it with the expected result ${expValue}.

9. Add a listener

Add view result tree to see if the final test result is correct.

3. Test results

The expected result is consistent with the returned result, and the result tree is displayed in green, indicating that the assertion is passed. The following figure shows the results of some interface tests:

 

Four. Summary

This issue introduces JMeter to use csv to read parameters for batch interface testing. It can be used when the project time is urgent and the test time is relatively short, which can improve the efficiency of the test. At the same time, csv is easy to manage, and can be supplemented at any time according to test cases to improve test coverage. If there are other more convenient methods, welcome to discuss with the editor.

Finally, a modest effort

Thanks to everyone who read my article carefully, although it is not a very valuable thing, if you can use it, you can take it away:

 These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey, and I hope it can help you too!

Information acquisition method:

Guess you like

Origin blog.csdn.net/qq_56271699/article/details/131331633