How to write automated test cases, it is said that this is the most complete......

foreword

Automated testing is the use of specialized software tools to validate software solutions, which often involves automated functions as part of the testing process. The most common objects for test automation are .

  • Test Management and Defect Management
  • Unit and unit integration tests
  • function test
  • Regression Testing
  • Non-functional testing such as performance and scalability

The writing of automated test cases is the core of project automation. Reasonable use case design is the key to ensuring automation benefits and practicability, and it also directly determines whether automation scripts are scalable and maintainable.

Automated test case selection

Automated testing is mainly used in the verification and regression of basic functions. For functions that are constantly modified during the project iteration process, the efficiency of manual testing is much higher than that of automated testing.

Therefore, before we automate, we need to select basic functions for automation.

In this process, we can choose from manual test cases, or we can write a set of test cases specifically for automation.

In the early stages of automation, it is recommended to pick from manual test cases. On the one hand, the coverage of manual test cases is the most comprehensive, which can ensure the comprehensiveness of the test;

On the other hand, it will also improve the test efficiency.
Our principles for selecting use cases are: clear, simple, basic, and small-change functions.

Automated test case writing

After selecting the appropriate use cases, it is the process of writing automation use cases through code. This process mainly includes three steps: data presetting, use case writing and use case post-setting.

1. Data preset

Before writing use cases, we need to prepare some data to ensure that the use cases can actually be executed. For example, if we are testing a web page login function, we need the URL parameters of the system, a user name and password that can be logged in;

We need to test the function of deleting files, so we need to upload a file in advance. This file can be preset in advance, or an upload operation can be performed before performing the delete operation; which method to preset data needs to be selected according to the actual situation of the project. .

We separate data presetting and use case writing to reduce the coupling between use cases and ensure that the execution result of the previous use case will not affect the next use case. In addition, it facilitates the maintenance and modification of use cases.

2. Use case writing

After we have prepared the test data, we will start writing automated use cases. During the writing process, we need to pay attention to the following aspects:

Familiar with the business. Automated testing is for business system services. Only by fully understanding the business and clarifying how to automate manual test cases can the quality of use cases be guaranteed.

Use variables. Usually, we need to manage the variables in a unified way and write them into the configuration file, which is convenient for unified modification. For example: we need to test a business system, which includes a test environment and a production environment. We need to flexibly apply automation scripts to each environment. At this time, we need to write system parameters such as url into configuration files for easy modification and migrate.

Write down the operation process. Code comments are essential when writing operational procedures. How does each step work and what functions need to be verified.

Set up checkpoints. In the process of writing test cases, it is necessary to set reasonable checkpoints, add assertions, and judge whether the test cases are executed successfully. After the use case is executed, it is the key to automated testing to compare the expected results with the actual results, output the test results, and clarify whether the function is successfully executed. Use case execution without adding assertions is meaningless.

3. Post-positioning of use cases

Post-positioning of a use case refers to the operation after the execution of the use case is completed, corresponding to the data preset, and it is for automatic cyclic execution.

For example: we need to test the file upload function. After the use case is executed, the file needs to be deleted to facilitate the next automatic execution.

In addition, we should perform some reasonable checks after the use case is placed. For example, in the previous step, if we failed to delete the file, it will still affect the next operation. Therefore, we need to check some core files in combination with the actual situation of the project to ensure the smooth execution of automation.

Use case writing specification

In the process of writing use cases, we need to abide by some norms to improve the quality of use cases. Mainly include: continuity, independence, integrity, reusability, maintainability and logical partitioning.

1. Continuity

Ensure the continuity between use cases and ensure that use cases can be executed in batches. For example, when we are performing UI automation, we must ensure that the execution interface of the next operation is entered after the previous operation.

2. Independence

The use cases should be independent of each other to ensure that the execution result of the previous use case will not affect the execution of the next use case. In this way, the problem can be more clearly located. In addition, it is necessary to ensure that the execution of one use case does not modify the data of the next use case.

3. Integrity

Each use case needs to have the whole process of data preparation, operation process, assertion and post-use case, and can specify the specific test content according to the use case.

4. Reusability

Similar to the public code developed, we need to abstract the atomic operations of automated testing and provide them to other use cases, which can reduce development costs

5. Maintainability

The name of the use case should be clear, so that the name is clear; add clear comments to each step and each variable; there are clear instructions on which are preset data, which are check items, and expected results; the steps of the use case should be simple and clear

6. Logical block

Carry out logical blocks according to certain rules (for example, it can be divided according to different functions) to ensure the independence of logical blocks, and a single functional use case can be extracted for verification.

下面是我整理的2023年最全的软件测试工程师学习知识架构体系图

1. Necessary knowledge of Linux

As the most popular software environment system, linux must be mastered. The current recruitment requirements require linux ability.

2. Shell script

Master shell scripts, including shell basics and applications, shell logic control, shell logic functions, etc.

3. Principles of Internet Programs

The only way to automate: basic knowledge of front-end development and necessary knowledge of Internet networks.

4. Mysql database

Software test engineers must have Mysql database knowledge, not just the basic "addition, deletion, modification and query".

5. Packet capture tool

Fiddler, Wireshark, Sniffer, Tcpdump and various packet capture tools are suitable for various projects, and there is always one suitable for you.

6. Interface testing tools

Interface testing artifact, a powerful tool you can't avoid: Jmeter. Small and flexible: Postman.

7. Web automation test Java&Pyhton

Understand the purpose of automation, master testng&unittest automation framework, and assertion and log processing.

8. Interface automation and mobile phone automation

Professional interface calling and testing solutions. Build a complete web and interface automation framework, which is used by Appium as a whole.

9. Agile testing & TestOps construction

Unveiling the mystery of TestOps, the continuous integration of the Jenkins framework is familiar.

10. Performance Test & Security Test

The other side of software testing: performance testing and security testing, choose the right direction, and work hard to climb the pit!


The above is a knowledge architecture diagram of the development direction of Python automated test engineers that I compiled for you. I hope everyone can complete the construction of such a system within 1-2 years according to this system. It can be said that this process will make you miserable, but as long as you get through it. Later life will be much easier. As the saying goes, everything is difficult at the beginning, as long as you take the first step, you are already halfway to success. The ancients said, "If you don't accumulate steps, you can't reach a thousand miles." When you look back on this journey after completion, you will definitely be moved. a lot.

As someone who has been here, I also hope that everyone will avoid some detours. If you don’t want to experience the feeling of not being able to find information when learning, no one answering questions, and giving up after a few days of persistence, here I will share with you some learning about software testing. Resources, I hope to help you on the way forward.

​These materials should be the most comprehensive and complete preparation warehouse for friends who want to learn [software testing]. This warehouse has also accompanied me through the most difficult journey, and I hope it can help you too! Everything should be done as early as possible, especially in the technical industry, we must improve our technical skills. I hope to be helpful!

insert image description here

Guess you like

Origin blog.csdn.net/weixin_54696666/article/details/131170559
Recommended