Exploration on the application of traffic recording and playback tools in the field of automated testing

Introduction: With the increasing changes in the technical architecture of Agricultural Bank of China and the continuous innovation of business scenarios, testing work is facing many problems and challenges such as cumbersome data structure, high case maintenance costs and uneven quality, which are mainly reflected in the following four aspects:

First, during system architecture upgrades and code reconstruction, a large number of original interfaces need to be regression tested; second, for business scenarios with complex logic, regression testing takes up a lot of time in the process of multi-version iteration; third, early entry of automation cases and later maintenance links require manual intervention, and the labor cost is high; fourthly, when transaction abnormalities occur in the production environment, the timeliness of problem solving directly depends to a large extent on the completion of tasks by developers and testers in the test environment. Efficiency in problem reproduction and debugging.

In summary, the improvement of test quality and test efficiency through the research and innovation of new technologies in the field of testing is of particular significance to the development of current testing work.

01 Overview of traffic recording and playback technology

Traffic recording and playback technology can quickly record the interface traffic generated during application operation according to certain filtering rules. The recorded content includes request messages and response messages of the interface. The messages stored during the recording process can be played back in the specified environment at any time. Traffic recording and playback scenarios can be applied in the functional testing phase to achieve regression verification, or in the version verification phase to achieve automatic transaction regression. Traffic recording and playback technology is of great significance in simplifying test case writing, improving test efficiency, and enhancing test scenario coverage .

picture

Figure 1 Traffic recording and playback process

According to the location of traffic recording, traffic recording and playback technology can be roughly divided into the following three categories: web server-based recording (customized web server operating system to implement application request recording), network protocol stack-based recording (by monitoring the network protocol port on the network card , using data packet copying to implement request recording) and application-based recording (using AOP aspect-oriented programming in applications to implement request recording). Their advantages and disadvantages are detailed in the table below.

Insert image description here
Table 1 Comparison of traffic recording and playback technologies

02 Design Plan

Based on the pain points in daily testing work, the Testing Department of the Tianjin R&D Department of the Agricultural Bank of China R&D Center set up a special task in July 2022 to use open source + self-research methods to build a traffic recording and playback tool, and achieve it through application layer recording. Configuration management, node monitoring, traffic management, traffic playback execution, batch execution, batch result analysis and other functions.

The traffic recording and playback platform is mainly divided into two parts: the agent module and the management module. The proxy module is used to monitor application traffic, process playback requests, and send recording and playback information to the management module for processing and storage; the management module is used for configuration management, module management, recording traffic query, and playback.

picture

Figure 2 Overall architecture of traffic recording and playback tool

The traffic recording and playback tool adopts a development architecture that separates the front and back ends. Users only need to install a probe on the application to realize traffic recording and playback operations. The access process and installation process are simple and friendly. After the access is completed, users can complete configuration creation, traffic recording and playback result query in one stop by accessing the unified web interface.

picture

Figure 3 Traffic recording and playback tool operating architecture

03 Innovative functional design

1. Data tiering strategy

Considering that during actual use, the application will generate a large amount of recording traffic, in order to achieve fast query and retrieval, the traffic recording and playback tool uses Elasticsearch to store online traffic data and playback result data, and can achieve millisecond-level processing with millions of data volumes. Quick query response. At the same time, MySql is used to store smaller management data, and the queue function of Redis is used to implement sequential playback of batch traffic.

picture

Figure 4 Schematic diagram of data layering

2. Batch playback and result query functions

The batch playback function can add the recorded traffic data into a batch through manual screening. It supports playback of the traffic data in the order of call occurrence during recording to simulate mixed transaction scenarios. Applicable to the following scenarios:

①The execution of cases has dependencies before and after, and related cases can be added to a batch and executed sequentially;

② After executing a stage of cases, including a large number of forward or reverse case scenarios of various mixed transactions, the traffic cases executed within a time period can be created as a batch and executed in sequence.

picture

Figure 5 Batch playback application scenario

Batch execution provides functions such as batch result statistics and batch execution pass rate trend display, helping testers understand the execution status of application interfaces in a timely manner, and provides testers with a reference for timely modification and execution of use cases.

picture

Figure 6 Batch execution result statistics

picture

Figure 7 Batch execution success rate trend statistics

3. Message comparison checkpoint

After the playback operation is executed and before the playback data is written, the transaction response message during recording and the transaction response message played back are compared for consistency to determine whether the playback operation is successful.

The playback results will be affected to a certain extent by the consistency of environmental data and noise fields such as random numbers, timestamps, and auto-incremented data contained in the interface. In order to reduce the cost of manual comparison and judgment and improve the automation level of the playback process, the tool uses checkpoints to achieve noise reduction and filtering. Checkpoints are usually configured as fields that are decisive for interface operations, such as response codes, etc. If the checkpoint fields are consistent, the difference value of the noise field is ignored and the playback result is determined to be successful.

picture

Figure 8 Message comparison checkpoint

4. Message header replacement

In the process of web application playback, we often encounter the problem that data cannot be played back normally due to user session expiration. In order to ensure that the recorded traffic can be continuously played back and used, the message header replacement function during batch execution is provided, and the parameter values ​​of the nodes in the headers in the message can be updated in real time.

5. Case generation and export

For recorded traffic cases, it is supported to be exported as JSON files with collection V2 specifications, which can be imported by interface testing tools such as Postman and Postwoman, thereby realizing case conversion and reuse without the need for manual assembly of message bodies, simplifying the use case writing process.

6. Life cycle management function

It supports users to flexibly configure the life cycle of traffic data, and can customize cleaning dimensions according to different environments of different applications. For traffic that has not been added to the batch and is no longer executed, it will be cleaned regularly according to the cleaning rules; for traffic that has been added to the batch, permanent storage and permanent playback can be supported.

picture

Figure 9 Traffic life cycle management

04 Application results

Currently, the traffic recording and playback tool is being gradually promoted in the Tianjin R&D Department of the Agricultural Bank of China R&D Center. More than 20 application modules have been connected, of which 67% are web applications, 13% are online applications, and 20% are mobile applications. The total number of recording interfaces reaches 4.06 million, and the batch playback success rate can reach more than 85% after process optimization and case adjustment.

picture

Table 2 Pilot promotion situation

Summarize:

The traffic recording and playback platform provides a new method for automated interface testing, which can be applied to multiple scenarios such as version verification and regression testing. Using the idea of ​​traffic as cases, online traffic is converted into interface test cases, thus greatly reducing the human investment in the test data preparation and script writing stages. In addition, using online traffic as test data can more realistically and comprehensively cover business scenarios than manually constructed test data, and improve the ability to discover problems through use cases. The application and promotion of traffic recording and playback tools in the testing field will be of great significance to improve testing efficiency and reduce labor costs and automation tool usage costs.

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:

Insert image description here

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/qq_48811377/article/details/132856532