Traditional Culture Encyclopedia - Traditional virtues - How to write automated and friendly test cases
How to write automated and friendly test cases
A good test case should be separated from the data as much as possible in the expression of the executed step. For example, if there is an ATM withdrawal function, there may be the following situations:
1) Log in with the correct password.
2) Incorrect password login
3) The password was entered incorrectly for three consecutive times, and the card was locked.
4) No balance can be withdrawn.
5) Try to withdraw more money than the balance.
6) Try to withdraw the money equal to the balance (considering the handling fee).
6) The withdrawal amount is greater than the current limit.
7) The withdrawal amount is greater than the limit of the day.
8) The number of withdrawals is greater than the limit.
etc
No matter what use case design methodology you use as a guide, as this simple example, experienced people should be able to see that many steps here can be reused, which can be summarized as follows (only the operation steps are listed here, and the feedback results in system interaction are omitted):
1) card->; Answer: Enter the password-> B: Press the "OK" key-> Repeat A-B
2) Answer: Select the withdrawal function-> B: Fill in the withdrawal amount-> Click the "Confirm Withdrawal" button-> Withdraw cash-> Repeat A-D
So we only need to write two sets of relatively complete steps, and use parameters to represent passwords and withdrawal amounts. Is this a lot easier?
2. Separate preparation of basic test data.
The input data in the first example is relatively simple, but we still need to consider a question: what kind of specific data do we input in the test? What is the "correct password"? What is "money is greater than balance"?
correct
In large-scale application systems, the relationship between data and preparation process will be very complicated, and even there will be data imported, transmitted or calculated by other external systems. It is better to prepare these test data in advance.
Import the system before each periodic test. A typical example, suppose you are required to test several complex financial statements separately, and use other modules and external systems to create data one by one, which will be wrong.
This is usually time-consuming and laborious. At this time, the preparation of basic data is particularly important, so as to ensure the efficiency of the test work and the accuracy of the test results.
If possible, it is best to prepare complex basic test data in advance, similar to the simple example here.
Valid bank card, account number 1234567890, password 66666, with RMB 1000, and so on. Prepare these contents in advance (you can use automated tools to prepare or guide them)
Write existing data into your separate test data preparation document instead of describing it in all cases.
3. Pre-conditions and post-conditions of test cases
Except for ...
In addition to the data mentioned in the second point, at the test case level, you must meet some conditions before you can start execution. For example, prepare an IE under the initial setting conditions.
Browsers and XP systems with old versions of software installed. These reusable access conditions cannot be considered as a specific use case step, but as a setting.
Part or prerequisite.
For postconditions or postconditions-
Conditions, we often use it for some treatment or recycling. For example, if we want to repeat the test with the same account, the balance of all the money will be zero.
, you can reset the account balance through some steps or database scripts. Similarly, you set the browser to disable Cookie for a use case. Do I need to go back to the default settings after executing the use case?
And then what?
Organize these steps into a relatively independent operation unit, and you only need to quote them in specific use cases, which will facilitate the understanding of use cases and can be reused in many places.
By the way, for some conditions similar to software operating environment, such as the combination of three operating systems and three browsers in the installation configuration test, we can put it at the level of the test set without writing multiple use cases, and it is only expressed as an environmental parameter of the test set in the management system of test planning and execution.
4. Common business operations (knowledge base)
For a large-scale application, such as a banking system, development and testing is a long-term and continuous process, and such a system is very suitable for introducing automated testing. The business logic is complex and the test technology is demanding. It often uses tools from different vendors and various scripting languages (such as Shell, Python, etc. ), and there are many legacy scripts available.
These script units that complete some predetermined business operations can be directly borrowed. In order to manage these reusable resources at the company and product level, a good way is to mark them with numbers, such as KB_PRJ0 1_Module02_XXX, and manage them centrally so that they can be called in future use cases.
rise
For example, in the banking test, we need to simulate the interface with UnionPay, so that the test account can make foreign exchange payment, obtain response information and save the results. This may be a complicated bottom-level processing flow, which is not suitable for ordinary employees.
Need, also have no power to master. At this time, package them into Shell scripts or gadgets, use them well, and archive them uniformly. In future project tests, just call them. such as
This can greatly improve the efficiency of automatic testing of modules with related interfaces.
According to some common problems in the preliminary work, the following supplements are made on how to write test cases (not limited to automated tests):
recommend
Not recommended
Describe the content of the example clearly, emphasize how to operate, verify what, and then expect what the result is.
Copy the requirements and contents in the design documents; Described as: under what conditions, what will the logic be like? This is not operable for readers and executors of test cases.
The expected results should be specific, such as: what is the system response; What is the result number; Which page the user is taken to; What success messages are displayed; What is the modification result of this record in the background or database?
Description: "Verify that the system returns correct results"; "Display of page elements is consistent with specifications"; "Operation successful" and other abstract statements.
Application software with strong business logic can organize use cases with business process as the main line.
Organize use cases in the form of pages.
Use cases are hierarchically organized in the form of tree structure of modules, functions, test types, basic business flows and alternative business flows. Use use case management tools.
The flat organizational structure of Word format is not conducive to management and reading.
Use an attribute field to establish the mapping between use cases and document chapters, such as Spec.
Unable to meet the requirements, it is difficult to calculate the future use case coverage and test execution coverage.
Each module, function and a set of test cases of a specific business are independent and not coupled.
There are dependencies between use cases, which cannot be achieved: 30% of use cases are selected for regression testing.
When time and cost allow, try to make the use case granularity "a different operation, get different results, just write a separate use case".
There are still conditional branches in the operation steps and even the expected results in the use case.
For complex business operation processes, such as "one-time sequential form signing process" and "one-time complete credit granting process", some large-scale test cases that run through the whole business process are added separately.
For long-term business operations, there are only scattered detailed use cases.
Use cases are prioritized to facilitate the selection of core business or user-intensive use cases in regression testing.
Use cases have no definition of priority and importance.
- Previous article:Fishing Town, known as "God's Whip".
- Next article:There is good pure music with wood, which needs Japanese style.
- Related articles
- Who is the oldest old man in Nanling County?
- What are the fermentation engineering products?
- Advantages and disadvantages of thermal printers
- The practice of small handmade flower baskets
- Types and unlocking methods of password locks
- What is Changzhou Sixian?
- Who is stronger, the CPU's SATA controller or the Southbridge's SATA controller?
- Simple clay sculpture made by hand
- Foreign wooden dolls
- How to stand on ballet toes