Using Jmeter for http interface testing

 

Foreword:

  This article mainly tests the http interface and uses the Jmeter tool to implement it.

  The Jmter tool was originally designed for performance testing, and it has been relatively mature in implementing calls to various interfaces. Therefore, this time, the Jmeter tool is directly used to complete the test of the Http interface.

 

1. The overall plan for developing interface test cases:

  • Step 1: We need to analyze the test requirements and get the interface documentation provided by the development;
  • Step 2: Sort out the interface test cases from the interface description document, which should include detailed input and output data, as well as clear formats and checkpoints.
  • Step 3: Review the interface test cases with the development.
  • Step 4: Combine with the development library, prepare the input parameter data and output parameter data in the interface test case, and organize them into csv format files.
  • Step 5: Combine the interface test case document and the data document in csv format to do the automated case development of the interface test case.

 

2. Application scenarios of interface automation:

 The currently designed automated interface test case has two running scenarios:

  1. Pre-testing, development self-testing: After a new automated interface test case is developed, it is directly sent to the corresponding development of the interface, and arranged to be executed in the development local environment. Once the interface development is confirmed and the interface development is completed, the interface test case will be executed. Basically, the test results can be obtained in real time, which is convenient for developers to make judgments quickly. [The way to develop local operation is to open the JMeter tool, import the JMX file, and start executing it.


  2. Regression testing: After the local development test is passed, or the entire requirement manual test is passed, the automated interface test cases are classified and sorted, and the cases that need to be included in the regression test are selected, and the test data is re-prepared in the continuous integration environment. To incorporate the case into the continuous integration job, these interface test cases for regression need to be configured to the continuous integration platform to run automatically.

 

3. Preparation of the interface test environment

 

Fourth, create a project:

  1. Open Jmeter : After downloading Jmeter, double-click the jmeter.bat file in the bin directory:

2. Add a thread group : Right-click on the "Test Plan" --> Add --> threads (Users) --> Thread Group, add a test scene setting component, and generally set to 1 "thread number" in the interface test , and set the "cycle times" according to the number of test data.

3. Add "HTTP Cookie Manager ":

4. Add the "Http request default value " component, which is very useful when the system under test has a unique access domain name and port:

5. On the "HTTP Request Default" component configuration page, fill in the domain name and port of the system under test, the version of the HTTP request implementation package and the specific protocol type. All "HTTP Samplers" in the thread group can use this setting by default.

6. Add the Sampler of "HTTP Request" in "Thread Group"

7. On the HTTP request setting page, enter the details of the interface under test, including the request path, the corresponding request method, and the list of parameters sent with the request:

8. Set a checkpoint : add a "response assertion" to the "HTTP request" corresponding to the tested interface

9. Add the existence judgment of the regular expression of the corresponding result on the setting page:

10. Add a listener: it is convenient to view the results after running

operation result:

The above steps complete the creation of a simple test case, and complex test cases are extended on this basis. For the interface test case developed with Jmeter tool, a subsystem is recommended to be placed in the same  "test plan", and the process test can be distinguished by "thread group", which is also convenient to set different test data numbers. The relatively independent interfaces can be placed in a thread group to complete the test sequentially.  

  流程性接口的测试:如果要测试的接口可以组成一个流程,只需要顺序添加多个“HTTP 请求”的Sampler,各请求之间可以提取需要在上下文传递的数据作为参数,以保证流程中数据的一致性。

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324816923&siteId=291194637