Talking about how to design an automated testing framework

The benefits of the test framework, such as fast regression to improve test efficiency and test coverage, will not be discussed here. Here we mainly discuss what is included in the automation framework and how to design a test framework.

1. What is an automated testing framework?

It is a collection of tools consisting of one or more automated test basic modules, automated test management modules, and automated test statistics modules.

Taking the common front-end UI test as an example, a test framework roughly includes modules such as test objects, test components, basic classes and functions, tool classes, test data, exception handling, test logs, assertions, and test reports.

When designing the test framework, we should combine these modules organically as much as possible, effectively organize and apply the scripts coherently, and improve the maintainability and readability of the test scripts.

2. There is no universal test framework, the one that is suitable for your own project and can improve work efficiency is a good framework.

Due to the variety of application system technologies, almost no test framework can be applied to multiple projects and reflect its due value. Therefore, in general, we need to customize our test framework according to the project itself. Commonly used are data-driven, keywords drive and a mix of both ways.

Data Driven (DDT)

If the business logic of the system under test is fixed or changes little, we can use data-driven to ensure test coverage through different data. Usually, the data is stored in an external file or database and is automatically obtained at runtime. It is characterized by the separation of data and test scripts. Based on the modular test library, one driver script can execute multiple similar tests, which makes it very easy to create new tests.

keyword driven

Combine data with keywords to describe how to use the data to perform the test. This approach has the advantage of being data-driven, while enabling non-programmers to create new types of tests.

3. Design framework ideas:

High cohesion and low coupling

High cohesion means that each module completes its own functions independently as much as possible, and does not depend on the code outside the module; low coupling means the complexity of the interface between modules, such as reducing the calls between methods as much as possible inside the class, otherwise A change in one method affects another method that calls it.

For example, you have to do two functions: read and write text files, read and write word, and you can put different methods in one class for the same IO, high cohesion.

For example, if you write a class, "person", "person" has its own name, age and other attributes, and each "person" has a dog as its own attribute, you can combine the attributes of "person" with "person" "The dog's attributes are all written in the "human" class, which becomes a high coupling. However, the dog's attributes are stripped out and written as the "dog" class, and only one pair of "dog" is placed in the "human" class. As a reference to the object, this "dog" class can be used as an attribute of "person", or it can be used for other purposes. i.e. low coupling

Script separation:

Objects, test data, and business logic are separated from each other and called flexibly, which can achieve obvious results in front-end UI testing. We can use the PageObject design pattern to separate objects from business logic, and use DataProvider to separate data and business logic.

Modular design use cases, reusable scripts

If time is sufficient and the project provides support, testing can be performed in the following order: page object - function point - business logic - business process.

From the perspective of implementation, it is: first test the underlying page operation object, realize the verification of the function point by calling the operation object and business logic, and then realize the verification of the business process by calling the business logic combination function point. Different business processes are completely reusable for the bottom-level operating components and middle-level function point functions, and the only difference is the difference in the business logic called or the difference in test data. The advantage of this is that the scripts are independent of each other, code reuse, and easy to maintain. If there are new business processes, existing codes can be called to combine.

Encapsulation Basic Method

For some more general methods, it can be encapsulated, such as log, assert, exception handling, file read and write operations, database read and write operations, saving page screenshots, etc. It can be called directly in the test case when needed.

How to carry out automated testing

  • Grasp the pain points in the business testing work and the pain points of the leadership, communicate more and communicate more, and give priority to solving the pain points at the grassroots level. I believe that a good leader will see your sense of responsibility and dedication;

  • Technology selection and scheme feasibility research require more time and energy. Some people are impatient and do it quickly in the early stage. If the direction is wrong at the beginning, the gain will outweigh the loss in the end;

  • If it is a more complex solution, try to separate the front and back ends as much as possible to ensure the independence and integration of each module, decoupling and not disintegration, so as to be flexible and scalable, and be prepared for the next big game.

Finally: The complete software testing video tutorial below has been sorted out and uploaded, and friends who need it can get it by themselves [Guaranteed 100% free]

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.

Guess you like

Origin blog.csdn.net/AI_Green/article/details/132571414