How to do the interface test, read this article in 5 minutes to figure it out thoroughly

0 1. General project structure

02. What is an interface

Interface: A unified access method provided by the server program to the outside world, usually using the 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, and then the client will perform different processing and display according to the data content after receiving the data returned by the interface.

03. Why do interface tests

A. In the company, the client and the server are usually developed by different teams. During the project development process, the development progress of the client and the server is inconsistent. For example, the development of the server is completed first. Conduct interface testing to ensure that the server logic and return data are correct, and then test the client. Or some testing departments specialize in testing the server-side development team, so their test object is the interface.

B. When testing certain 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 use tools to bypass the front end and directly call the server interface. If the server does not do anything related Logical judgments will result in data errors. Including whether to encrypt key information during interface data transmission. Therefore, it must be tested separately for the server interface .

C. After the development and testing, you can run the interface test of the server through the tool first to ensure that the interface test cases are all passed, and quickly judge whether the server interface meets expectations. Then test it through the UI interface. Otherwise, if there are bugs in the interface, there must be bugs in the front-end page.

0 4. Interface testing 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 is also possible.

For the specific use of Jmeter, please refer to the document "Jmeter Interface Tool Combat"

Interface testing process:

Like ordinary web testing, requirements analysis, test case writing, test execution, bug submission, regression testing, and test report submission are also performed first.

0 5. The focus of interface testing

1. Input

The input mainly refers to the input parameters of the interface. In our usual tests, we will first consider the normal input parameters and the abnormal input parameters. The abnormal conditions include: parameter exceptions and data exceptions. The use case design is mostly used for equivalence. Class Partitioning and Boundary Value Analysis

  • normal input

    Normal input parameters are easy to understand, that is, according to the input parameter standards of the interface design document, input normal parameters, and the response returns normally according to the agreed conditions of the interface design document

  • Parameter exception

    Parameter exceptions include: empty parameters, more or less parameters, wrong parameters

  • data exception

    Data exception: data type error, non-null parameter is empty, length does not meet the design, data out of range, illegal members, special characters or sensitive characters, abnormal parameter data with related relationships, etc.

2. Business logic

Like UI-based functional testing, interface testing also needs to understand the business logic behind the interface. For the processing logic of the business process, we can consider it from different dimensions such as the restriction conditions of the input parameters, the operation objects of the event, and the state transition of the business.

  • Constraint Analysis

    ①  Numerical restrictions: dictionaries, grades, industry-related restrictions, amount restrictions, score restrictions, etc.

    ②Status  restrictions: valid|invalid, online|offline, blacklisted|whitewashed, etc.

    ③  Restriction of relationship: existence or non-existence, binding or unbinding, etc.

    ④Limitation  of permissions: administrators, ordinary users, etc.

  • object analysis

    Object analysis is mainly to operate on legal and illegal objects. For example, if a bank card user recharges the card, there may be: user A recharges with a card other than user A; user A recharges with his own card, and the card has expired ; User A uses his own card to recharge, and the card is blacklisted or reported lost.

  • Analysis of State Transitions

    For example, in the payment business, if the payment is successful first, the refund will be issued after the order is cancelled. If the payment is unsuccessful again, it means that the payment has failed. Controllable, whether there is an abnormal state, how to deal with empty state business, etc.

  • timing analysis

    In some complex activities, an activity is performed by a series of actions in a specified order. These actions form an action flow, which must be executed in sequence in order to wait for the expected result. Then other branch actions that occur during the execution process What will the program do?

3. Output

When considering exceptions, we usually think of normal situations and invalid situations, but they may not cover all error codes, and 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, invalid task, server exception, etc., add the value of errorcode to design more use cases

This kind of design use case based on output can find out whether the front-end and back-end output results are normal, whether the prompt is friendly, whether there is sensitive information in the prompt, etc.

4. Database operation

  • Whether the business data storage is normal, whether there is duplicate data storage, and whether there are garbled characters

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

  • Whether each field in the table meets 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 concurrency supported by the interface?

  • How many times the interface can handle transactions per second (TPS)

  • The average response time (RT) of the interface

  • Consumption of server resources by interfaces (CPU, memory, network, disk)

7. Compatibility

Interface testing does not need to consider client compatibility, mainly data compatibility . 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. Others

  • Idempotency: It means that 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.

Take the simplest example:

That is payment . The user pays after purchasing the product, and the payment deduction is successful, but when the result is returned, the network is abnormal. At this time, the money has been deducted. When the user clicks the button again, the system should refuse to pay at this time, and prompt "Cannot pay repeatedly". It is equivalent to that the second payment will not have any effect. When doing interface testing, for some interfaces with idempotence requirements, it is necessary to test for idempotence.

Usually, Jmeter can be used to continuously call the interface twice to perform operations such as payment and submission to test idempotency.

END study arrangement!

Finally, I would like to thank everyone who has read my article carefully. Seeing the fans’ growth and attention all the way, there is always a need for reciprocity. Although it is not a very valuable thing, if you can use it, you can take it directly.

These materials should be the most comprehensive and complete preparation warehouse for friends who do [software testing]. This warehouse has also accompanied me through the most difficult journey, and I hope it can help you too!

Finally: You can get a 216-page software test engineer interview collection document for free on my VX public account: [Programmer Xiaohao] . And the corresponding video learning tutorials are free to share! , which includes basic knowledge, Linux essentials, Shell, Internet program principles, Mysql database, packet capture tool topics, interface testing tools, advanced testing-Python programming, Web automated testing, APP automated testing, interface automated testing, testing Advanced continuous integration, test framework development test framework, performance testing, security testing, etc. You can also interact with me

Guess you like

Origin blog.csdn.net/myh919/article/details/131424958