What is interface testing, how to do interface testing?

Compared with the functional test of the starting point, the "interface test" is professional and tall, which makes some junior testers "daunting". Don't worry, in fact, interface testing is also a type of functional testing, which is a functional test for interfaces.

Written in the front: This article refers to "Advancement and Practice of Full-stack Technology for Test Engineers" written by Mr. Ru Bingsheng, and deletes and supplements based on my own understanding.

1. What is interface testing?

Software interface refers to the interface for interaction between different modules of the software. What we usually call API (Application Programming Interface) is the agreement for the connection between different modules of the software system.

Interface testing is the testing of the interface of each module of the software.

2. Why should we pay attention to interface testing?

In recent years, the scale of software has become larger and larger, and the software system has become more and more complex. The robustness and fault tolerance of the system cannot be guaranteed only from the test of the user interface, and the earlier the problem is found, the lower the cost of repair. The following figure is a traditional software testing pyramid model proposed by Mike Cohn:

The pyramid model tells us:

The lower the test level, the easier it is to locate the problem;

The higher the test level, the higher the maintenance cost;

The higher the level of testing, the higher the cost of repair.

However, since Internet products pursue functions quickly and go online, there is basically no extra time for developers or testers to do enough unit tests; the time for unit tests is reserved in time, and frequent iterations will also make unit tests at a low level. The state of constant writing. Therefore, the unit testing of Internet products also has certain targeted strategies, generally covering unit testing of core modules with relatively stable businesses and services. In this case, API testing becomes especially important. The main reasons are as follows:

  1. The development, debugging and execution efficiency of API test cases is relatively high
  2. API is relatively stable
  3. The execution stability of API test cases is much higher than that of GUI tests
  4. Many Internet products now adopt the microservice architecture. Under this architecture, if the API test of each service is done well, the quality of the overall product will be guaranteed.

Therefore, Internet products generally adopt a diamond-shaped testing strategy:

3. What are the benefits of interface testing?

The previous section introduced why we should pay attention to interface testing. What are the benefits of doing interface testing?

Realize shifting the test to the left.
The GUI test of the user interface is to simulate the behavior of real users using the software. It is located at the top of the test. After a problem is found, the cost of locating and repairing it is relatively high. API testing can realize the left shift of the test, that is, the front-end and back-end separated projects. When the back-end development is completed, the interface test can be carried out without waiting for the front-end. It can ensure that problems are detected as early as possible, and the cost of repairing problems can be reduced.
Reduce maintenance cost
Compared with the user interface, the interface is relatively stable, and the maintenance cost is low
to improve the test efficiency.
On the one hand, because the interface does not depend on any operation on the interface during execution, its execution stability is far higher than that of the GUI, so it can be automated and improved. Test efficiency;
on the other hand, some commonly used interface use cases can be made into small tools (or directly execute scripts), and some data preparation and construction scenarios during the test process can be directly used; also, it needs to be
repeated Executed regression scenarios can directly execute use cases.
Conducive to bug location
Obviously, the problems found through the interface are back-end problems, and you can directly find the developer responsible for the interface; if the problem is only found in the user interface, you can directly find the front-end developer. This test strategy can clarify the scope of bugs, reduce the cost of bug location
and ensure the security, robustness and fault tolerance of the system

Some input that cannot be done through the UI can be easily realized through the interface. For example, in  what is test thinking - the core skills of test engineers,  the example of WeChat balance payment is from the scene:

Only from the user interface, negative numbers and non-full numbers cannot be input; but from the interface point of view, these values ​​can be used as input parameters.

4. How to design and organize interface test cases?

First, clarify the scope of interface testing. As mentioned in the second section, due to the "fastness" of the Internet, API testing has become particularly important. But don't all APIs have to be tested? --no. Just like unit testing, API testing also needs to consider cost-effectiveness, so we generally choose core business modules for API testing. Since the core modules of different businesses are different, they will not be discussed here.

Just introduced, the interface test is a functional test for the interface. Therefore, the use case design principles of interface testing and functional testing are the same: scenario analysis must flexibly use test thinking (what is test thinking – the core skills of test engineers), commonly used use case design methods are equivalence class division, boundary value etc. (Must learn for getting started with software testing - how to design test cases). What is the difference between the two?

1) The test objects are different

Functional testing: mainly tests the specific functions of the application

Interface test: Mainly test whether the input and output of the interface between modules in the application meet expectations

2) The purpose of the test is different

Functional testing: ensuring that the specific functionality of the application is consistent with the requirements document

Interface test: test whether the input and output of the interface between modules in the application meet expectations, and whether the interaction with other modules is OK

3) The focus of the test is different

Functional testing: focus on user interface and functionality

Interface testing: focus on business logic

4) Different testing tools

Functional testing: mainly manual direct operation of the user interface

Interface testing: you need to use interface testing tools, such as postman, jmeter, etc., more to implement code-based test suites

5) Test extensions are different

Functional testing: the user interface changes frequently, and sufficient exploratory testing can be done

Interface testing: The interface is relatively stable, which is conducive to automation to ensure business logic. For example, the refactoring of the user interface, if the interface remains unchanged, the user interface can be changed at will, and at the same time, the implemented interface automation is used to ensure the business logic. But "automation" itself does not scale, and it cannot replace exploratory testing with manual testing.

4.1 Testing of a single interface

Through the above sections, we have learned that the interface is the agreement between different modules of the software system. Therefore, interface testing is more standardized, usually three standard steps:

  1. Prepare test data
  2. make a request
  3. Verify the response result

The points that need to be paid attention to during interface testing are:

  1. URL address: specific interface url
  2. Request method: GET, POST, PUT, DELETE, etc.
  3. Request Header (Header): The header information carried when sending the application. Usually some authentication information: authentication/cookie, response data format: content-type and so on. Of course, the response data will also return some header information.
  4. Request parameters (Parameter): GET is in the form of key-value pairs, and POST parameters are in the body
  5. Response content (Response): the return code and return content of the interface, that is, output. This part is usually verified.

4.2 Testing of Multiple Interfaces

In actual business scenarios, usually a single front-end operation may trigger a series of back-end API calls, so API test cases are generally not a single API call, but a series, and often need to be used in the latter API call The result returned by an API call also needs to determine which API should be called later based on the returned result of the previous API call. Therefore, the resolution of these two problems directly affects the realization of multiple interface test cases.

How to efficiently obtain the sequence of API calls triggered by a single front-end operation?

Ask the Developer
This is the most straightforward method. But often asking one will disturb the developers, and the other is that we are not professional enough.
Reading and developing code
requires a certain programming foundation

3. Refer to the developer's detailed design documents
. Generally, more standardized detailed design documents or interface documents will have business logic diagrams, indicating the calling sequence between interfaces.

4. Packet capture
You can use packet capture tools such as Fiddler to obtain it yourself without relying on developers.

5. View logs

Through logs based on user behavior, API call sequences can be obtained.

How to use the result returned by the previous API call in the latter API call?

Manual inspection
is naturally possible, but the efficiency is relatively low.
Automated implementation
The standardization of the interface enables the automation of the verification and reference of the results, which not only can verify the business process, but also improve the efficiency of verification.

If you use postman, you can automatically generate verification codes. However, when a large number of test cases need to be executed frequently, interface-based API tests such as Postman cannot meet the needs. So a code-based API testing framework emerged. Typical ones are Java-based OkHttp and Unirest, python-based http.client and Requests, Node.js-based Native and Request, etc. Some large enterprises will also develop their own API testing framework in combination with their own business. Each framework has its own advantages and disadvantages, and the ideas are interlinked. The general idea is as follows:

The main process of the business is extracted, and each main process corresponds to a test suite, that is, the test suite
can be added to the test suite of the main process for some abnormal scenarios, which will not affect the final result; a test suite can also be established separately to reduce the impact on Interference with the main business process;
parameters that support multiple values ​​can be cross-covered in different test suites (orthogonal experimental method)

5. Common interview questions

  1. What protocol interface is used in the project?
  2. Tip: Generally, there are HTTP, HTTPS, RPC, etc. Then I will continue to ask questions based on the answers~
  3. What request methods does the HTTP interface have?
  4. Tips: Commonly used GET, POST, PUT, DELETE, etc.
  5. The return code of the HTTP interface
  6. Tips: 2xx, 3xx, 4xx, 5xx
  7. What are the benefits of interface testing?
  8. How is interface testing done?
  9. Tip: Go back to the process and design
  10. What are the commonly used request headers, and what are the request headers for?
  11. The difference between cookie and session, UA, etc.
  12. How to distinguish front-end and back-end bugs?

6. Thinking and conclusion

Interface testing is becoming more and more important in the work of test engineers, so it is also a necessary skill for professional TEs.

This article briefly introduces the background and advantages of interface testing, and also briefly mentions the design and organization part, and there is no use of design tools and frameworks. In fact, if you want to talk about this part in detail, every tool and every framework is a big topic. This article just provides a simple idea, and each tester needs to think more and summarize more.

If I have a chance, I will slowly summarize and share~Fighting! Let's encourage each other!

Finally, I would like to thank everyone who has read my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it away directly: [Collect at the end of the article]


     [The following is the most complete software test engineer learning knowledge architecture system diagram + full set of materials I compiled in 2023]


1. From entry to mastery of Python programming

2. Interface automation project actual combat

3. Actual Combat of Web Automation Project


4. Actual Combat of App Automation Project

5. Resume of first-tier manufacturers


6. Test and develop DevOps system

7. Commonly used automated testing tools


Eight, JMeter performance test

9. Summary (little surprise at the end)

life is long so add oil. Every effort will not be let down, as long as you persevere, there will be rewards in the end. Cherish your time and pursue your dreams. Don't forget the original intention, forge ahead. Your future is in your hands!

Life is short, time is precious, we cannot predict what will happen in the future, but we can grasp the present moment. Cherish every day and work hard to make yourself stronger and better. Firm belief, persistent pursuit, success will eventually belong to you!

Only by constantly challenging yourself can you constantly surpass yourself. Persist in pursuing your dreams and move forward bravely, and you will find that the process of struggle is so beautiful and worthwhile. Believe in yourself, you can do it! 

Guess you like

Origin blog.csdn.net/nhb687096/article/details/132298324