A Scheme of Interface Automation Testing

foreword

Last year, we split the project, and each subsystem after the split was gradually changed to data exchange through the interface, and the interface test was also put on the agenda. After a period of exploration, the interface automation testing solution has become more and more perfect. Today, I will give you a detailed explanation.

plan

At present, our interfaces are all using the http protocol. The basic principle of the test is to simulate the front-end (client) sending data to the server and get the corresponding response data, so as to judge whether the interface can exchange data normally. In the process of testing, I have tried two ways, one is to use the performance testing tool Jmeter to simulate the client to initiate http requests, and the other is to use python scripts to directly write scripts to simulate the client to initiate http requests.

Using Jmeter tool configuration, you need to be familiar with how to use Jmeter to perform performance testing. It can be done through corresponding configuration, but it is not flexible enough. For example, some fields need to undergo specific encryption processing, which cannot be done directly through Jmeter.

So choose to use python script directly, and simulate http request can be done with just a few lines of code. But just simulating requests is not the ultimate goal, and it also needs to be easy to use. People who don’t know how to code will also maintain our test cases, so the current form is formed, following some basic principles of the test framework, business logic and test scripts are separated, Test scripts are separated from test data. The general framework is shown in the figure below: The insert image description here
directory structure is as follows: insert image description here
All test cases are managed by Excel, and the test data can be configured in Excel or saved in the test data file as needed. The format of the test case is as follows: The insert image description here
insert image description here
insert image description here
format of the log is as follows: insert image description here
After the test is completed, the abnormal interface can be sent to the relevant person by email. The above is a general introduction to the interface test solution. The following will tell you how to configure the use case.

how to test

The core script of the test has been built, and there will be no major changes in the future. The test of the subsequent interface can be completed by maintaining the Excel table of the test case. Whether it is the test of the new interface or the regression of the old interface, how to write an interface test What about use cases?

1. Open the Excel form of the test case, fill in the case number, interface description information, domain name and request address of the interface under test. insert image description here
2. There are two ways to select the interface request, one is POST and the other is GET, which can be selected according to the actual situation. insert image description here
3. Select the way the interface receives data. There are currently three types, Form type, the requested data will be urlencode encoded, generally this type, the interface of the official website is mainly this type; Data type, which directly requests the interface in the form of text, Without urlencode encoding, most of the engine's interfaces are like this. When selecting the Data type, there are two types of data requested, one is to configure the json string directly in Excel, the other is to fill in the text file path, and the file is also json Strings, mainly when the data of the post is large, such as saving cases, are not easy to manage in Excel. The File type represents the uploaded file, and the File type is selected when testing the upload. insert image description here
4. Configure the data to be sent to the interface, as shown in the figure below. You need to configure the correct test data according to the type selected in the previous step. Except for the file path, the data must be a standard json format string.insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_42434318/article/details/109498227