After reading this article, you can find out exactly how to do interface testing

01 common project architecture

02 what is an interface

Interface: a unified access method provided by the server program. It usually uses HTTP protocol to execute different business logic through different URLs, different request types (GET, POST) and different parameters.

Most of the business operations of the client need to call the server interface to obtain some data or trigger some business. Then, after the client gets the data returned by the interface, it will do different processing and display according to the data content.

03 why do interface tests

A. In the company, the client and server are usually developed by different teams. In the process of project development, the development progress of the client and server is inconsistent. For example, when the server is developed first, you can first test the interface of the server to ensure that the logic and returned data of the server are correct, and then test the client. Or some testing departments specifically test the server development team, so their test object is the interface.

B. When testing some services, you can't just test through the front end, such as user registration. The front end restricts the user name from being empty, but some people may directly call the server interface by bypassing the front end through tools. If the server does not make relevant logical judgment, data errors will be caused. Including whether key information is encrypted during interface data transmission. Therefore, the server interface must be tested separately.

C. After the development and test, you can run the interface test of the service side through the tool to ensure that the interface test cases pass, and quickly judge whether the service side interface meets the expectations. Then test through the UI interface. Otherwise, the interface has a bug, and the front-end page must have a bug.

04 interface test tools and processes

Common HTTP interface testing tools include Jmeter, Postman, SoupUI, etc. Jmeter is widely used in enterprises.

Jmeter is an open source and free interface testing tool, which can test the function and performance of the interface. Interface automation can also be realized.

For specific use of Jmeter, please refer to the actual operation of Jmeter interface tools

picture

Interface test process:

Like ordinary web testing, it is also to conduct requirements analysis, write test cases, execute tests, submit bug s, regression tests, submit test reports, etc.

05 focus of interface test

1. Input

Input mainly refers to the input parameters of the interface. In our normal test, we will first consider the normal input parameters and abnormal input parameters. The abnormal conditions include parameter exceptions and data exceptions. The use case design mainly uses equivalence class division and boundary value analysis

Normal input parameters

Normal input parameters are well understood, that is, input normal parameters according to the input criteria of the interface design document, and the response returns normally according to the agreed conditions of the interface design document

Parameter exception

Parameter exceptions include: empty parameter, multiple or fewer parameters, and wrong parameters

Data exception

Data exception: data type error, non empty parameter is empty, length does not meet the design, data outside the range, illegal members, special characters or sensitive characters, parameter data exception with association relationship, etc

2. Business logic

Like UI based function testing, interface testing also needs to understand the business logic behind the interface. For the processing logic of business process, we can consider it from different dimensions, such as parameter constraints, event operation objects, business state transition and so on

Limiting condition analysis

① Numerical restrictions: dictionary, grade, industry related restrictions, amount restrictions, score restrictions, etc

② Status limit: valid|Invalid, online|Offline, pull black|Wash white, etc

③ Relationship restrictions: existence or non existence, binding or unbinding, etc

④ Restrictions on permissions: administrators, ordinary users, etc


Object analysis

Object analysis mainly operates on legal and illegal objects. For example, if a bank card user recharges the card, there may be: user A Use non users A Recharge your card; user A Recharge with your own card. The card has expired; user A Use your own card to recharge. The card is blacklist or loss report.


Analysis of state transition

For example, for payment businesses, payment is successful first, and refund will be made after cancellation. If payment is not successful again, payment fails. Is the switching between statuses normal? How to display the status, whether it is controllable, whether there is an abnormal status, and how to deal with the business in an empty status when it is not operated smoothly according to the normal business


Time series analysis

In some complex activities, an activity is carried out by a series of actions in a specified order. These actions form an action flow. They are executed in this order before they can wait for the expected results. What will other branch action programs do during execution?

3. Output

When considering exceptions, we usually think of normal situations and invalid situations, but they may not cover all error codes. The error codes returned by the interface definition can help us supplement this part of the use cases, such as network exceptions, invalid rules, invalid parameters, invalid business ID S, invalid tasks, server exceptions, etc, Adding the values of errorcode can design more use cases

By designing the use case according to the output, you can find out whether the front and rear ends output the results normally, whether the prompt is friendly, and whether there is sensitive information

4. Database operation

Whether business data warehousing is normal, whether there is duplicate data warehousing, and whether there is garbled code

Whether the data update is normal, especially the time field, and whether the time is in the format of 24-hour system

Do the fields in the table meet expectations

5. Security

Whether sensitive information is encrypted (such as user name, bank account number, password, transfer amount)

6. Performance

What is the maximum number of concurrent interfaces supported

How many services can the interface handle per second( TPS)

Average response time of interface( RT)

Interface consumption of server resources( CPU,Memory, network, disk)

7. Compatibility

The interface test does not need to consider the compatibility of the client, but mainly the compatibility of the data. For example, whether the historical data of the old interface is compatible, and whether the old data can be processed normally with the new interface.

8. Other

Idempotency: that is, the results of one request or multiple requests initiated by the user for the same operation are consistent, and there will be no side effects due to multiple clicks.


The simplest example:

That is, payment. The user pays after purchasing goods, and the payment deduction is successful, but the network is abnormal when the result is returned. At this time, the money has been deducted, and the user clicks the button again. At this time, the system should refuse to pay and prompt "cannot repeat payment". Equivalent to the second payment will not have any effect. During interface testing, for some interfaces with idempotence requirements, idempotence needs to be tested.


Generally, it can be used Jmeter Call the interface for payment, submission and other operations twice in a row to test idempotency.

Keywords: Java unit testing

Added by Carline on Mon, 18 Oct 2021 05:20:41 +0300