Summary of experience in using Jmeter for APP interface testing

use tools:
  Fiddler、 Jmeter
   Test steps:
  1. Confirm the interface
  Obtain the interface document from the developer. The interface document should include the complete functional interface, interface request method, interface request URL, interface request parameters, and interface return parameters.
  If the current project does not have an interface document, you can use fiddler to capture the APP for confirmation.
Fiddler can refer to the method of capturing packets on mobile phones: http://blog.csdn.NET/whorus1/article/details/50673740
  Operate the APP on the mobile phone, and then capture the corresponding network interaction information in Fiddler (multiple interface interactions may be designed in one function). In the captured information, you can see the interface request method, interface request URL, interface request parameters, and interface return parameters.
  2. Writing test scripts in Jmeter
  (1) Add a thread group to the test plan (right-click on the test plan, add-Threads-thread group).
  You can change the name of the thread group to the name of the test project.
  During performance testing , you can control the number of concurrent users by configuring the parameters in the thread properties:
  Number of threads: the number of virtual users, that is, the number of concurrent users, one thread represents one virtual user;
  Ramp-Up Period: The time for all threads to start, in s. Through this parameter, the startup interval between each thread can be set to prevent too much performance pressure on the computer;
  Number of loops: the number of test loops, if "Forever" is checked, then all threads will keep sending requests until the script is manually stopped;
  (2) Add an HTTP request to the thread group (right-click on the thread group, add-Sampler-HTTP request).
  You can change the name to the name of the interface to be tested;
  Fill in the address and port number of the requesting server in the web server;
  Fill in the protocol of the HTTP request in the protocol, which can be http or https, we generally use http;
  Select the HTTP request method in the method. The available methods include GET, POST, HEAD, PUT, OPTIONS, TRACE, DELETE; (The interface methods in our project mainly use GET and PUT. The APP does not directly interact with the server, and there is a unified interface platform in the middle, so the interface request of the GET method should also use POST to interact.)
  Fill in the URL of the interface request in the path;
  Request parameters: If it is a GET method request, the request parameters can be written directly after the URL; if it is a POST method, you need to fill in the data containing the request parameters in the Body Data (Body Data can be obtained from the package captured by Fiddler , copy the data in the Inspectors-TextView captured by Fiddler into the data packet to the Body data);
  (3) Add the HTTP header manager to the thread group (right-click on the thread group, add-configuration element-HTTP request header manager).
  The configuration is as follows:
  (4) Add a listener (right-click on the thread group, add-Listener-XXX).
  The main configuration is complete, and a listener needs to be added to view the test results. Generally we use view result tree and aggregate report view.
  View the result tree: In the result tree, the test results of each interface request will be displayed in a tree structure, including sampler results, requests, and response data. In the response data, you can see the data returned by the network side, which can be displayed in the interface document. Expect the returned parameters to be compared to determine whether the return is correct. In the result tree, you can visually see the results of the interface test by color, green is passed, red is failed.
  Aggregated report: From the aggregated report, we can obtain a lot of information, including the response time, throughput, and pass rate of the interface, which is very useful in the performance test of the interface.

 

The meanings of the parameters in the table are as follows:
  (5) Add response assertion (add-assert-response assertion).
  When looking at the test results, we will find that sometimes the results given by Jmeter still pass when the data returned by the network side does not meet the requirements. At this time, we need to use assertions to determine whether the returned data from the network meets the requirements.
  For example, we can add an assertion to check if the returned message contains the keyword "errMsg" to determine the error message:
  First add a corresponding assertion, select the response text in the response field to be tested, select include in the pattern matching rule, check No, add a mention in the pattern to be tested, and enter the keyword "errMsg";
  It means that the network return result does not contain "errMsg" will be judged as passed.
  In addition, we can also add an assertion result from the listener, and in the assertion result, we can view the detailed return information of the assertion.
  3. Other supplements
  Variables are defined using CSV Data Set Config.
  For example, what should we do when we want to test multi-user login? You can configure multiple threads in the thread properties, but this only means that the same user logs in multiple times, and multiple different users need to enter different usernames and passwords. Of course, we can write multiple login HTTP requests, each with different parameters, but this is too silly.
  At this time, we can define two variables to represent the username and password through CSV DataSet Config, and then pass in different values ​​to achieve multi-user login:
  1. We add a CSV DataSet Config in the login case (Add-Configuration Element-CSV Data Set Config).
  Filename: Specify the file to read the username and password, we will write all the username and password to this file;
  FileEncoding::: The file encoding format for writing the username and password. When not writing, the default is ANSI
  VaribleNames: Define the variable names in the text file username=user and password=pwd, separated by commas.
  2. We go to the filename path above to create the file and write the username and password. Separate the username and password with a comma, and wrap lines between different usernames and passwords.
  3. Change the original username and password to the variable name in the Jmeter script. Since we are using the Post method, modify it in Body Data:

Guess you like

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