Experience summary of App interface testing using JMeter

Source: Internet
Author: User

Using tools:

Fiddler, Jmeter

Test steps: 1. Confirm Interface

From the developer to obtain the interface document, the interface document should include the full functional interface, interface request method, interface request URL, interface request parameters, interface return parameters.

If the current project does not have an interface document, you can use Fiddler to check the app for a packet capture.

Fiddler the method of grasping the mobile phone can refer to: http://blog.csdn.NET/whorus1/article/details/50673740

The app is manipulated on the phone, and then the corresponding network interaction information can be crawled in the Fiddler (a feature may be designed to interact with multiple interfaces). In the crawled information, we can see the interface request method, interface request URL, interface request parameter, interface return parameter.

2. Write a test script in JMeter

1. Add a thread group to the test plan (right-click on the test plan, add the-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 parameters in the thread properties:

Number of threads: the number of virtual users, that is, the number of concurrent, a thread represents a virtual user;

Ramp-up Period: The time that all threads start, in units s. This parameter can be used to set the start interval between each thread to prevent the computer from causing too much performance stress;

Number of cycles: the number of times to test the loop, and if "Forever" is checked, all threads will continue to send the request until the script is manually stopped;

2. Add an HTTP request to the thread group (right-click on the thread group to add the-sampler-http request).

The name can be changed to the name of the interface under test;

Fill in the Web server with the address and port number of the requesting server;

Protocol to fill in the HTTP request protocol, can be http or HTTPS, we generally use HTTP;

Select the method of the HTTP request in the method, the available methods include GET, POST, HEAD, PUT, OPTIONS, TRACE, DELETE, (the interface method in our project uses mainly get and PUT, in the current easy-to-Web project because the app does not directly interact with the server , there is a unified interface platform in the middle, so the interface request of the Get method also uses post to interact. )

Enter the URL of the interface request in the path;

Request parameters: If it is a GET method request, the request parameter is written directly behind the URL, if it is the method of post, you need to fill in the body data containing the request parameter data (body data can be obtained from the Fiddler Grab Packet, Copy the data from the Fiddler crawl to the Inspectors-textview in the data packet to the body data);

3. Add the HTTP header manager in the thread group (right-click on the thread group, add-configure symbol-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 the listener needs to be added to view the test results. Generally we use view results tree and aggregated reports to view.

View result tree: In the result tree, the test results for each interface request are presented in a tree structure, including the sampler results, request, response data, the data returned on the network side can be seen in the response data, and the parameters expected to be returned in the interface document are compared to determine if the return is correct. In the result tree through the color can visually see the results of the interface test, green for passing, red for failure.

Aggregated reports: We can get more information from aggregated reports, including interface response time, throughput, pass rate, etc., which is useful in performance testing of interfaces.

The parameters in the table have the following meanings:

5. Add a response assertion (add-assert-response assertion).

When we look at the test results, we find that sometimes the results of JMeter are still passed when the network side returns data does not meet the requirements. At this point we need to use assertions to determine whether the network's return data meets the requirements.

For example, we can add an assertion to check whether the return 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, tick No, add a reference to the mode you want to test, and enter the keyword "errmsg";

This means that checking the network return results that do not contain "errmsg" will be judged as passed.

In addition, we can add an assertion result from the listener to see the detailed return information of the assertion in the assertion results.

3. Other additions

Define the variable using the CSV Data Set config.

For example, what do we want to do when we test a multiuser login? Multiple threads can be configured in the thread properties, but this is just the same user logging in multiple times, and many different users need to enter a different user name password. Of course we can write multiple login HTTP requests, each of which input different parameters, but this is silly.

This time we can use the CSV DataSet config to define two variables to represent the user name and password, and then pass in different values to achieve multi-user login:

1. We add a CSV DataSet config (Add-config component-csv Data Set config) to the login case.

FileName: Specifies the file to read the user name and password, we will write all the user name password to the file;

FileEncoding:: Write the user name password file encoding format, do not write when the default is ANSI

Variblenames: Defines a variable name in a text file user name =user and password =pwd, the variables are separated by commas.

2. We create the file in the path above filename and write the user name password, the user name and password separated by commas, different user name password line.

3, to the JMeter script to change the original user name password to the variable name, because we use the Post method, so to the body data modified:

Experience summary of App interface testing using JMeter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.