What is interface testing? Process steps of interface testing

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.2. Multi-group data test

5.4.3. Interface dependency processing

5.4.4. Interface structure judgment: assertion

5.5. Interface test execution

5.6. Interface test report


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?

  1. 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.
  2. The focus of the test is to check the data exchange, transfer and control management process, and the mutual logical dependencies between the systems
  3. 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

  1. You can find a lot of bugs that cannot be found by operating on the page
  2. Check the system's exception handling capabilities
  3. Check system security and stability
  4. The front end can be changed at will, the interface is tested, and the back end does not need to be changed
  5. It can bring efficient defect monitoring and management capabilities to the project, and can improve the overall quality of the software
  6. 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:

  1. The correctness of the interface is guaranteed by multiple parties and must be tested
  2. According to the interface type, reasonably conduct test analysis and pay attention to the key points of the test
  3. Focus on business logic analysis, including forward and reverse operations
  4. Focus on data file inspection

Points to really pay attention to:

  1. 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
  2. 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?
  3. 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
  4. 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
  5. 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:

  1. interface address URL ;
  2. Request method : get, post, delete, put, option. . . ;
  3. Request parameters : parameters added after the URL, request body parameters, request header parameters;
  4. 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

  1. why—why to conduct interface testing;
  2. what—what is included in the test interface;
  3. when—the start and end time of different stages of the test interface;
  4. where—corresponding interface documents, storage location of interface defects, test environment, etc.;
  5. who—the personnel involved in the project, which interfaces are assigned to whom;
  6. 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

insert image description here

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:

Postman's built-in dynamic parameters and custom dynamic parameters and assertion methods_Momo18S Blog-CSDN Blog_postman built-in parameters

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

Postman runs in batches - Programmer Sought

Guess you like

Origin blog.csdn.net/weixin_37600187/article/details/128186481