Table of contents
1. What is interface testing & how to test it
2. The benefits of interface testing
3. How to do a good job in interface testing
Fourth, the principle of interface testing
5. Interface test process & use case design
5.1. Interface document analysis
5.1.1. Diagram of interface composition
5.2. Develop interface test plan
5.3. Write interface test cases & review
5.3.1. Interface test case template
5.4. Interface test data & script
5.4.1. Public data maintenance
5.4.3. Interface dependency processing
5.4.4. Interface structure judgment: assertion
1. What is interface testing & how to test it
Generally, we can call it interface testing such as component interface data interaction testing within the system and interface data interaction testing between different systems.
So how should we test the interface?
- Interface testing is to judge whether the interface meets or meets the corresponding functional, security, and performance requirements by testing the corresponding input and output parameter information of different situations.
- The focus of the test is to check the data exchange, transfer and control management process, and the mutual logical dependencies between the systems
- To put it simply: "Interface testing is to replace the front-end page or third-party users to verify whether the back-end interface implementation complies with the interface specification when there is no front-end page or the front-end has not been completed ."
2. The benefits of interface testing
It can test the stability and correctness of the outgoing interface, and can quickly locate the defects of the back-end regardless of the influence of the front-end, improving the efficiency of testing
- You can find a lot of bugs that cannot be found by operating on the page
- Check the system's exception handling capabilities
- Check system security and stability
- The front end can be changed at will, the interface is tested, and the back end does not need to be changed
- It can bring efficient defect monitoring and management capabilities to the project, and can improve the overall quality of the software
- The more complex the project, the larger the system, the more frequently the interface test is used, the more obvious the effect
3. How to do a good job in interface testing
Official formula:
- The correctness of the interface is guaranteed by multiple parties and must be tested
- According to the interface type, reasonably conduct test analysis and pay attention to the key points of the test
- Focus on business logic analysis, including forward and reverse operations
- Focus on data file inspection
Points to really pay attention to:
- Test the function implementation of the interface , check the data request of different parameters, the data returned by the interface and the expected result, that is, the consistency of the specification of the interface document
- Test the robustness (fault tolerance) of the interface . For example, if the data type passed is wrong or empty data, special characters, etc. are inconsistent with the interface specification, can it be handled normally?
- Test the boundary value of interface parameters , for example, if the data passed exceeds the range stipulated by the interface specification, or whether the data can be processed normally when the data is large enough or negative
- Test the performance of the interface , the time for the interface to process and respond to data, concurrency, etc. Of course, this involves the optimization of code implementation, which needs to be communicated with developers
- Test the security of the interface , such as whether sensitive data such as login user name and password are displayed in plain text, and whether the interface requiring permission is exposed to the outside
Fourth, the principle of interface testing
By simulating the client or web browser to send a request to the server, the server processes the received data after receiving the request, and at the same time returns a response to the client. Our simulated client judges the data after receiving the returned data. How to judge?
1. Judging whether the request is correct or not, the system will return a 200 status code if the default request is successful, and return a status code of 400, 404, 500, etc. if the request is wrong
2. Judgment data: the correctness and completeness of the returned data
3. Judgment of security: Generally, the interface will not be exposed to the Internet and called by others at will. Generally, we will make some restrictions on the interface, such as the number of requests, the request frequency limit, etc.
To put it simply : find a tool that can be connected to the Internet, send a request to the interface server according to the interface document, get a response, and check whether the response conforms to the specification of the interface document
5. Interface test process & use case design
5.1. Interface document analysis
Analyze test requirements, interface api documents, be familiar with interface business, interface address, authentication method, input parameters, output parameters, error codes, etc. . .
Interface document analysis 4 elements:
- interface address URL ;
- Request method : get, post, delete, put, option. . . ;
- Request parameters : parameters added after the URL, request body parameters, request header parameters;
- Response result : a standard to determine whether the interface test is passed
5.1.1. Diagram of interface composition
5.2. Develop interface test plan
The test plan is basically the same as the functional test plan, which is the well-known 5w1h
- why—why to conduct interface testing;
- what—what is included in the test interface;
- when—the start and end time of different stages of the test interface;
- where—corresponding interface documents, storage location of interface defects, test environment, etc.;
- who—the personnel involved in the project, which interfaces are assigned to whom;
- how—which test tools and test methods are used for testing.
5.3. Write interface test cases & review
Interface use case idea:
1. Positive example : Input normal input parameters, the interface can successfully return data, generally consider the following aspects
All required parameters
All parameters (mandatory parameters + optional parameters)
Parameter combination (mandatory parameters + some optional parameters)
2. Counterexample:
Counter-example of authentication: the authentication code is empty, the authentication code is wrong, the authentication code has expired......
Parameter counterexample : parameter is empty, null, less parameters, more parameters, abnormal parameter type, abnormal parameter length (boundary value)
Error code coverage : depending on the business
Other error scenarios : interface blacklist, interface call limit, paging scenarios
5.3.1. Interface test case reference template
5.4. Interface test data & script
The reference documents are mainly based on the introduction documents related to the Postman tool that have been sorted out so far, and will continue to update other tool-related documents in the future.
5.4.1. Public data maintenance
1. There are a lot of repeated data definitions in the interface use case writing, each interface needs to write the server address, the server address is different in different environments , refer to [environment variables] to reduce server address changes, and modify the interface;
2. Between different interfaces, there will be a phenomenon of parameter passing, that is, the next interface needs to use the return value of a field of the previous interface . At this time, you can refer to [global variables] to solve the problem
1-2 Reference documents:
Postman's environment variables and global variables - Programmer Sought
3. For some interfaces, some fields need to generate new values every time. You can use the pre-script to set [customized global variables] for reference when calling the interface
3 Reference documents:
5.4.2. Multi-group data test
When testing some interfaces, it is necessary to execute multiple sets of test data simultaneously forward/reversely , create a CSV or JSON file, add relevant test data, and read the file. This is the famous data-driven test DDT
Reference documents:
Postman's CSV or JOSN file realizes data drive - Programmer Sought
5.4.3. Interface dependency processing
Reference documents:
Postman interface associations are extracted using regular expressions - Programmer Sought
Postman's environment variables and global variables - Programmer Sought
5.4.4. Interface structure judgment: assertion
Reference documents:
Analysis of Postman's common assertion functions - Programmer Sought
5.5. Interface test execution
Perform interface testing using the interface testing tool
List of commonly used testing tools :
- Postman: post/get interface combat, interface automation
- JMeter: post/get interface combat, interface performance, interface automation
- Pytest+Request+Allure+Instant Alarm: Interface Automation
- Fiddler/Charles: interface packet capture tool
- Loadrunner: Interface Performance
- Wireshark: can capture packets of various protocols for analysis
- Soapui: can do both interface testing and automated testing
- Apifox、poster、Httprequester。。。
5.6. Interface test report
Postman + Newman+ Jenkins or Jmeter+ Jenkins , realize continuous integration, output test report and send email
Reference documents:
Postman's Newman command line runs scripts to generate HTML reports - Programmer Sought