1. What is an interface test? Why do interface tests?

Interface test is a test to test the indirect interface of a system component. Interface testing is mainly used to detect the interaction points between external systems and internal subsystems. The focus of the test is to check the data exchange, transfer and control management process, as well as the logical interdependence between systems.

Due to the increasing complexity of today’s system, the cost of the traditional test method increases sharply and the test efficiency drops sharply, so it is necessary to do interface test. At the same time, interface testing is relatively easy to realize automatic continuous integration, and relatively stable compared with UI automation, which can reduce the labor cost and time of manual regression testing, shorten the test cycle, and support the demand of back-end rapid release. Continuous interface integration is the source of low cost and high benefit. At present, many systems are separated from the front and back end architectures. From the perspective of security, only relying on the front end to limit has completely failed to meet the security requirements of the system (it is too easy to bypass the front), and the back end also needs to control, in this case, it needs to be verified from the interface level. It is also necessary to verify whether the information transmitted at the front and back ends and log printing is encrypted and transmitted, especially the privacy information of users, such as ID cards and bank cards.

  1. What do back-end interface tests measure?

The graph below shows what the back-end interface test measures:

  1. How do I do interface tests?

In general, since the interface based on HTTP protocol is mainly called before and after the project, the sending and receiving of HTTP requests are simulated by tools or codes during interface testing. So let’s clean up the HTTP interface testing using the Jmeter tool.

3.1 Develop the overall scheme of interface test cases

Step 1: analyze the test requirements, and get the interface documentation provided by the development;

Step 2: sort out the interface test case from the interface specification document, which should include detailed input and output parameter data and clear format and checkpoint;

Step 3: Review interface test cases with development;

Step 4: Combined with the development library, prepare the input and output parameter data in the interface test case, and organize them into CSV files;

Step 5: Combined with the interface test case documents and CSV format data documents, do the automatic case development of interface test cases.

3.2 Application scenarios of Interface automation

The automated interface test case currently designed has two running scenarios:

(1) the development of test preconditions, self-test: a new interface automation test case development, after the completion of interface directly to the corresponding development, arrange in the development of the local environment, once the development validation complete interface development, begin to implement interface test cases, basically can get real-time test results, convenient to develop fast. (The way to develop a local run is to open the JMeter tool, import the JMX file, and start executing.)

(2) Regression test: Develop local after test pass, or the whole demand manually after the test pass, the automation interface test cases do sorting, pick out the need to include the cases in regression testing, in a continuous integration environment to prepare the test data, and put the case into the continuous integration of the job, the interface for regression test cases need to be configured to run automatically continuous integration platform.

3.3 Preparing an Interface Test Environment

Jdk1.6 or above: www.oracle.com/technetwork…

Jmeter, download address: jmeter.apache.org/download_jm…

The plug-in can be downloaded and installed at www.jmeter-plugins.org/

3.4 Creating a Project

1. Open Jmeter: After downloading Jmeter, double-click the jmeter.bat file in the bin directory:

    

2. Add a thread group: Right-click Test Plan > Add > Threads (Users) > Thread Groups to add a test scenario setting component. In the interface test, the component is generally set to one Thread number and the number of cycles is set according to the number of test data.

    

3. Add HTTP Cookie Manager:

    

4. Add the “Http Request Defaults” component, which works well when the system under test has a unique access domain name and port:

    

5. On the “HTTP Request Default” component configuration page, enter the domain name and port of the system under test, HTTP request implementation package version, and protocol type. All HTTP Samplers in the thread group can use these Settings by default.

    

6. Add “HTTP Request” Sampler in “Thread Group”

    

7. On the HTTP request setting page, input the detailed information of the tested interface, including the request path, corresponding request method, and the parameter list sent with the request:

    

8. Set checkpoints: Add Response Assertion to HTTP Request corresponding to the tested interface:

    

9. Add regular expression existence judgment for the corresponding result on the setting page:

    

10. Add listeners: easy to view the results after running

    

Running results:

    

The above steps completed the creation of a simple test case, and the complex test cases were expanded upon. In the interface test case developed with the Jmeter tool, it is recommended that one subsystem be placed in the same “test plan”, and that process tests be distinguished by “thread groups”, which makes it easy to set different numbers of test data. More independent interface, can be unified in a thread group, order to complete the test.

Testing of flow interface: If the interface to be tested can form a flow, it only needs to add several “HTTP request” Sampler in sequence, and the data that needs to be transmitted in context can be extracted from each request as parameters to ensure the consistency of data in the flow.

  1. Interface testing continuous integration

For interface test, continuous integration automation is the core content, we can achieve low cost and high income by means of automation. At present, we have realized interface automation, which is mainly applied in the regression stage. The degree of automation needs to be strengthened in the future, including but not limited to the following contents:

A) Process: in the regression stage, the coverage of abnormal interface scenarios is strengthened, and gradually extended to the system test and smoke test stages, and finally achieve the automation of the whole process.

B) Results presentation: richer results presentation, trend analysis, quality statistics and analysis, etc

C) Problem location: more accurate error information and logs are reported to facilitate problem recurrence and location.

D) Result verification: strengthen automatic verification ability, such as database information verification.

E) Code coverage: Constantly try to explore from the current black box to the white box to improve code coverage.

F) Performance requirements: Improve the performance testing system and monitor the interface performance indicators through automated means.

  1. Interface test quality assessment criteria

A) Whether business function coverage is complete

B) Whether business rule coverage is complete

C) Parameter verification meets requirements (boundaries, business rules)

D) Whether the coverage of interface exception scenarios is complete

E) Whether the interface coverage meets the requirements

F) Whether the code coverage meets the requirements

G) Whether the performance indicators meet the requirements

H) Whether the safety indicators meet the requirements