Interface testing based on Python automated testing framework

The previous article explained the content related to web UI, and this article talks about interface testing and automated testing framework.

Interface testing is a way to test data interaction between system components. It uses input parameters and corresponding output results under different circumstances to determine whether the interface meets or meets the corresponding functional and security requirements. Simply put, interface testing is to replace the front-end to verify whether the back-end implements or conforms to the interface specification.

Interface testing principle

Simulate the client to send a request message to the server. After receiving the request message, the server processes the corresponding message and returns a response to the client. The client accepts the response data and makes a judgment.

◆Request: Is it correct? The default request is to return 200 if the request is successful. If the request is incorrect, status codes such as 400, 405, 500, etc. will be returned. The error type will be determined based on the status code, such as parameter passing error or backend or server exception.

◆Check: In addition to checking the status of the returned data, you also need to check the correctness and completeness of the content of the returned data.

◆Security: The interface is generally not exposed to arbitrary calls on the Internet and needs to be subject to some restrictions, such as required login or restrictions on the number and frequency of requests, and encryption of passwords and other departmental content.

Interface test tool selection

1. Ready-made interface tools can do automated testing

◆Jmeter 、Postman

◆These two methods are common interface testing tools, but they are only suitable for testing simple interfaces without upper and lower parameter transfer. Some protocols or processes are difficult to implement because of their complexity.

2. Open source platform for automated testing

◆Metersphere 、apipost、apifox

◆These are open source interface automated testing platforms. Metersphere integrates interface, performance, and functional testing on one platform, which is very helpful for version iteration and defect management.

3. Write adapted interface automation code based on python

◆Pytest

◆A large number of interfaces, specific interfaces, encryption operations, and related operations trigger some components

◆The bottom layer of httprunner is executed using pytest

There are many tool options for interface testing, so our company chose to use python+pytest to develop the automation framework based on the three-layer automation dimension:

1. Use pytest to develop automation framework

◆Process screenshots + logs of each step

◆Highly integrated with project or product business

◆Environment initialization or clear data, complete customized implementation

2. The follow-up stage of automation: the company’s self-developed framework – patent

◆Testers need to understand the code, which is expensive but helps improve the underlying quality of the product.

3. The company’s own testing platform

◆Provide visual interactivity

◆Web page (css js html vue) + backend (java/python–django+flask)

Test latitude of interface testing

The interface test starts with the test of a single interface to ensure the correctness and robustness of the single interface test. Then, the business logic series connection of multiple interfaces is completed through the test of a single interface, and then the correctness detection of the business logic is completed from the perspective of business logic, such as picture:

picture

Interface test cases are designed according to three stages, namely function, performance and security. The three stages are considered from different points, as follows:

picture

Interface testing framework

The following introduces the testing framework based on Python+Pytest+Allure+gitlab+jira. The same framework based on PO mode as selenium is shown in the figure below:

picture

Automated test code structure

picture

The code writing ideas after the framework is written:

1. Base class encapsulation, encapsulate common methods such as sending requests, adding, deleting, modifying, and checking in the base class;

2. Write the interface code of the business layer

3. Write test case code, gradually supplement and improve the use cases based on the above use case layering, and put universal use cases that do not involve business into the base class.

The above is an overview of the interface testing and framework of automated testing.


              [The following is the most comprehensive software testing engineer learning knowledge architecture system diagram in 2023 that I compiled]


1. Introduction to Python programming to mastery

2. Practical implementation of interface automation projects

3. Web automation project actual combat


4. Practical implementation of App automation project

5. Resumes of first-tier manufacturers


6. Test and develop DevOps system

7. Commonly used automated testing tools


8. JMeter performance test

9. Summary (little surprise at the end)

life is long so add oil. Every effort will not be disappointed, as long as you persevere, you will eventually be rewarded. Cherish your time and pursue your dreams. Don’t forget your original intention and forge ahead. Your future is in your control!

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

Only by constantly challenging yourself can you constantly surpass yourself. Keep 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!

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

This information should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you!

Guess you like

Origin blog.csdn.net/NHB456789/article/details/135032610