90% of the test engineers use postman for interface testing in this way


1: Preparation before interface test

The interface test is a protocol based function black box test. Before the interface test, we should understand the interface information, and then know how to test an interface and how to completely verify the response value of the interface.

So the question is, where can I get the interface information? There are three common methods:

1. through packet capturing tools, such asfiddle,Charles get interface information

2. through the browser developer tool,Networks view interface request information

3. of course, the most direct and reliable is the interface document, which is the interface requirements document

The most basic interface documents of a specification should include:

  • Description of interface request address, request method and request header information

  • Interface input parameter description (including parameter type, required or not, length range, etc.)

  • Interface response example and response status code

At present, many companies do not have interface documents, but the importance of interfaces is not cumbersome here. I think testers should take the initiative to put forward them. Development needs to write interface documents, and they need to be more proactive in testing. The following is the interface document of swagger I wrote. You can refer to it:


2: Interface test practice

Generally, interface testing at the beginning is based on testing tools, such as interface debugging magic postman, which is used to debug and test interfaces for development and testing.

The interfaces demonstrated here are mock serve built with flask. Later, I will share how to build an interface project from 0

Example 1: Demo

Interface information:


Get type

The parameter limit is not required, indicating the data acquisition limit

We open postman and request the demo interface, as shown in the figure:

The demo interface can be operated simply without any parameters and request header information. Enter the interface address, select the interface request method, and click send to directly request success, or the interface response status code and response value. How do I request a get request if it has parameters? As shown in the figure:

Fill in parameters in params in the form of key value pairs. It is found that there is only one piece of data information in the info field of the interface response value at this time. Of course, when the limit is 2, two pieces of data will be returned. Careful friends may have found that the parameters of the get interface are directly spliced behind the URL, such as: The get interface can also directly request in the browser to obtain the response value


3: Understanding cookies

Query the train number information interface through an example 12306 to understand the cookies in the interface request header information, and open the browser developer tool to obtain the interface address, request method, parameters, response values, etc., as shown in the figure:

Then, for example 1, enter the interface address and parameters in postman and send the request. However, the request fails. Children, do you have many question marks

Then why is there no problem with this interface request in the web page? It fails when you go to postman. In fact, when web developers request this interface from the back end, they will send some website information of the browser, the user’s login status, the user’s browsing habits, etc. to the back end through cookies in the request headers, but postman will not. Then I will simulate adding the request header information in postman (the header information can be obtained in the browser), as shown in the figure:

Sure enough, the request was successful. Is it interesting to understand interface tests and cookies through two get interface instances. Next, let’s take a look at a post type interface. By the way, we can understand the common token, which is also a common question in the interview. How to test the interface authentication

4: Post interface of interface test practice

Interface information: address post type

The parameter username indicates the login user name

Password means the login password


As shown in the figure:

The post interface first selects the body parameter, and then enters the parameter to send the request. We can see that the login interface returns a token if the request succeeds, just like the ID card ID, which is unique to everyone. This token is the pass of this person.

Token authentication, in simple terms, means whether to log in. Generally speaking, all interfaces of a system need authentication before requesting. In other words, you must first request the login interface of the system and get the server response authentication before requesting other interfaces. It is generally placed in the request header or body parameter. If no token is sent to other interfaces, you will be prompted that you do not have permission to access or are not logged in

For the HTTP protocol, we have mastered the commongetandpostInterface tests. Of course, there are many other types of interface tests, such as delete, put, etc., as well as interfaces with form data input parameters, such as file upload interfaces

For interfaces with different protocols, such as WebService, we need to understand the Dubbo interface through examples. After understanding various types of interface testing, we can automate the interface and getA set of effective interface automation test scheme, you can independently package and build a test framework suitable for the project according to the actual test requirements.

Finally, those who don’t understand can pay attention to me,Click to view the home page to receive the video demonstration tutorialAuthor recording