1. Prepare for the interface test

Interface test is protocol-based function black box test, before the interface test, we need to understand the information of the interface, and then know how to test an interface, how to verify the response value of the interface.

So the question is, where do you get the interface information? There are three common ways:

1. Get interface information from a package capture tool such as Fiddle or Charles

2. Use the browser developer tool and Networks to view the interface request information

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

A standard interface document should basically include:

Description of the interface request address, request method, and request header

Interface input parameter description (including parameter type, mandatory, length range, etc.)

Interface response example and response status code

Now many companies do not have interface documentation, but the importance of the interface here is not redundant, I think testers should be proactive, development needs to write interface documentation, in the test work needs to be more proactive. Swagger interface documentation:

Two: interface test actual combat

Generally speaking, the first contact with interface testing is based on testing tools, such as interface debugging magic Postman, development and testing are used to debug and test the interface.

The demo interface is a Mock Serve built by Flask. How to build an interface project from zero will be shared later

Example 1: Demo

Interface information:

Address: 127.0.0.1:5000 / API/demo

GET the type

The parameter limit is optional, indicating the limit of obtaining data

We open Postman and request the Demo interface, as shown:

Because the demo interface can not fill in any parameters, and request header information, so the operation is very simple, input the interface address, select the interface request method, click Send directly request success, or the interface response status code, and response value. What if a GET request takes an argument? As shown in the figure:

If limit = 2, you will return 2 values. If limit = 2, you will return 2 values. Careful friends may have found the get the parameters of the interface directly joining together behind the url, such as: http://127.0.0.1:5000/api/demo? Limit =1, the get interface can also directly request in the browser, get the response value

Three: Understand cookies

Through an example 12306 interface for querying traffic information to understand the cookie in the interface request header information, open the browser developer tool to obtain the interface address, request method, parameters, response values, as shown in the figure:

Example 1: Enter the interface address and parameters in postman, and send the request. However, the request fails.

So why is there no problem with this interface request in the web page, but failed in postman? In fact, when a Web developer requests this interface to the backend, it sends some web information of the browser, user login status and user browsing habits to the backend through cookies in Request Headers, but Postman does not. I’ll simulate adding a request header to Postman (the header is available in the browser), as shown below:

The request was successfully received, and the cookie was successfully tested by two get interface instances. How to test the authentication of a post interface

Four: interface test actual combat post interface

Interface information: address 127.0.0.1:5000/ API/Login POST type

Username indicates the login username

Password Password indicates the login password

The content-type: application/json

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 is successful, just like the ID card ID, which everyone has and is unique. The token is the person’s pass.

Token authentication means whether to log in or not. Generally speaking, all interfaces in a system need authentication before making a request. In other words, you need to request the login interface of the system first and obtain the server authentication before making a request for other interfaces. If the request interface does not transfer the token, the system will prompt no access permission or login

We already know the get and POST interface tests for HTTP, but there are many other types of interface tests, such as DELETE, PUT, etc., as well as form-data interfaces, such as the file upload interface

So for interfaces of different protocols, such as WebService, we need to learn about dubbo interfaces through examples. When we understand various types of interface test, we can carry out interface automation, get a set of effective interface automation test program, and can independently package and build a test framework suitable for the project according to the actual test needs.

This article was first published in the public number: Programmer Yifan, pay attention to me to learn more software testing knowledge