How to write a good test case?

Tram Ho

In software testing, terms like test cases and errors are mentioned frequently. When planning application testing, it is estimated that 70% of the work is devoted to writing test cases and executing test cases.

However, what exactly is a test case? We define a test case as a written document that provides comprehensive information about what tests and how to test them. A test case includes information such as goals, descriptions, precise steps and most importantly the expected output of the planned test.

What is a good test case?

As a QA professional, Tester is well aware of the importance of test cases and writing test cases is an essential stage of the testing cycle. However, sometimes test cases are not written carefully leading to poor quality test cases. If the test case is written well and carefully, it will bring many benefits for individuals who run the test case, as well as for the project, benefits such as:

  • Reduce the effort of reviewing test cases and performing test cases

A well written test case is easy to understand and therefore takes less time to review and execute. In a team, it’s more likely that the test case implementation will be done by a member of the team who is not the one writing the test case, so good test cases always save time and reduce communication between members.

  • Identify gaps in the project life early

Test case design requires capturing all positive as well as negative scenarios. Recording those details requires an organized thought process and a full understanding of the application being tested, thereby helping to identify design and functional flaws.

  • Helps achieve maximum test coverage

Test case is an indicator that reflects the planned test scope. In process-oriented projects, each test case will be reviewed to determine the scope before being approved for implementation. Writing test cases will ensure that the test functions and perspectives, the test scope will not be missed.

What does a test case include?

Depending on the requirements of each project, the test case may be different. But usually a test case usually has the following main content

  • Test Case Name / Title: Shows what is the object to be tested (what function? Which screen? …)
  • Objective / Purpose of the test case: Shows the purpose of this test case
  • Preconditions: Shows prerequisites, such as dependencies or completed steps
  • Data test: This may not be necessary for every test case but some test cases require special input. It is therefore necessary to record these data so that the scenario can be accurately implemented
  • Test steps: Shows the details of the operations performed without any missing or redundant operations
  • Expected Results: Shows the desired output of the script
  • Pass / Fail Status: After performing the test will update the results in this field
  • Enviroment: Demonstrates the scenario environment to be performed
  • Comments: The note should be saved when performing this test case

How to write a better test case?

1. Create test cases from the perspective of the end user

The ultimate goal of creating test cases is to meet customer requirements. If we write a test case without our experience as an end user, then we are more likely to get errors or script that does not fit into the real world. So by always working with the product as an end user, we will see many migration flows that can cause errors.

2. Knowledge of the field of application

Software business knowledge is at the core of any software application. (for example, knowledge of banking and finance, knowledge of medical education or virtual money …) Business rules can change and can greatly affect business functions. Lack of knowledge of the application business will lead to not understanding the requirements, functions of the application, writing the wrong case of the test case will greatly affect the business, which can cause losses for customers.

So learn about the application’s business area to get a quick overview of the project functions and specifications.

3. Avoid assumptions

Do not assume anything, stick to the Specification Document. Assuming the features and functionality of the software application can create gaps between the specifications and the product being developed, this could also affect the business.

4. Attach relevant documents

There are always documents showing the required changes or problems related to the scenario under test. It is better that you record those documents in the test case. It helps keep track of major changes in your application at the time of product delivery or helps you understand confusing logic that cannot be explained by testing steps.

5. Avoid writing repetitive actions

If these scenarios need to be executed multiple times, please seek the help of Test Automation. It also helps reduce manual efforts and adds value to the product. Test cases should be written so that they can be reused by any other team for any other project.

6. A test case only tests one thing

Always make sure that the test case tests only one thing, if you try to test multiple conditions in a test case, tracking results and errors becomes very difficult.

8. Easy to understand test case language

Use concise and clear terms when writing test cases. Long steps like prose should not be described. Let’s start with a verb. A test case should not have too many operations.

For interface tests, attach images. For functional test cases, break down the function into parts and write each part in turn. Test case structure should be subdivided and clear, making the process of changing test cases easier.

9. Write independent test case

Test cases should not be dependent on other test cases, that is, you will be able to execute your own test case without depending on the results of other test cases.

Writing test cases is a time-consuming and fairly repetitive task, but if done carefully, it will make the testing process easier and more efficient.


Share the news now

Source : Viblo