Test cases are a critical component of software testing that help validate that an application functions as expected. As a beginner in software testing, learning how to write high-quality test cases with examples allows you to create effective test scenarios to thoroughly test your software. In this comprehensive guide, we will walk through the end-to-end process of writing test cases with examples for beginners.
What is a Test Case?
A test case represents a single scenario that tests a particular feature or functionality of an application. It consists of a set of conditions variables inputs, and expected results that help determine whether a specific function is working correctly.
In other words, a test case documents the steps necessary to validate that a piece of software conforms to the specified requirements. It allows testers to identify any defects or gaps in the software under test.
Here are some key characteristics of a good test case:
- Has a unique ID to identify the test
- Documents the test scenario, steps, and expected results
- Includes all the prerequisites, test data, and postconditions
- Follows a standard template for consistency
- Is simple, precise, and easy to follow
Components of a Test Case
A test case comprises several components that help testers execute the tests properly. The standard components in a test case are:
Test Case ID: A unique identifier to recognize the test case. For example, TC001, TC002.
Test Scenario: A brief description of the functionality being tested. For example, successfully logging in with valid credentials.
Prerequisites: The preconditions necessary to execute the test case, like user access, test data setup, etc.
Test Steps: Step-by-step instructions to perform the test.
Test Data: The data variables used for testing, such as usernames, passwords, etc.
Expected Result: The expected outcome when the test case is executed successfully.
Actual Result: The actual test execution outcome that can be compared with the expected result.
Status: The final test status like pass, fail, blocked, etc.
Postconditions: Additional steps to be performed after test execution such as cleanup.
How to Write Test Cases: 10 Steps
Follow these 10 steps to write comprehensive test cases:
1. Understand the Requirements
Review the software specifications and requirements documents to understand what needs to be tested. Identify the test scenarios, business and technical requirements.
2. Analyze the Product
Conduct exploratory testing sessions to study the application’s features and functionality. This helps determine the aspects to test.
3. Select a Test Case Design Technique
Choose a suitable test case design technique like boundary value analysis, equivalence partitioning to define test cases.
4. Create Test Case ID
Define a unique ID for each test case using a naming convention like TC001, TC002 for easy management.
5. Write Test Scenario
Document a high-level description of the test scenario in simple language. For example, successfully changing user password.
6. Specify Prerequisites
List any prerequisites for test execution like access permissions, test data setup, etc.
7. Outline Test Steps
Prepare step-by-step test case execution instructions using action words like enter, click, check.
8. Define Test Data
Determine the test inputs and variables needed, such as usernames, passwords, URLs.
9. List Expected Outcome
Specify the expected result that will confirm the test passes successfully.
10. Validate and Review
Validate test cases against requirements. Review to improve test coverage and remove duplicates.
Test Case Design Techniques
Choosing the right test case design technique helps generate optimal test cases to thoroughly test the software. Here are some popular techniques with examples:
1. Equivalence Partitioning
Divides input data into valid and invalid classes to reduce test cases.
Example: Validating age field allows only numeric values from 1 to 100.
Valid Equivalence Partition:Numeric values from 1 to 100
Invalid Equivalence Partition: Alphabets
2. Boundary Value Analysis
Tests boundary values of valid and invalid partitions.
Example: Valid age values: 1 to 100
Test Cases for BVA: 0,1,2,99,100,101
3. Decision Table Testing
Tests system behavior using a table with conditions and corresponding actions.
Example:
| Username | Password | Sign In |
|
How to write Test Cases (Test Case Example)
Let’s build a test case example based on a specific scenario. Here is a sample case.
- Test Case ID: #BST001
- Test Scenario: To authenticate a successful user login on Gmail.com
- Test Steps:
- The user navigates to Gmail.com.
- The user enters a registered email address in the ’email’ field.
- The user clicks the ‘Next’ button.
- The user enters the registered password.
- The user clicks ‘Sign In.’
- Prerequisites: A registered Gmail ID with a unique username and password.
- Browser: Chrome v 86. Device: Samsung Galaxy Tab S7.
- Test Data: Legitimate username and password.
- Expected/Intended Results: Once username and password are entered, the web page redirects to the user’s inbox, displaying and highlighting new emails at the top.
- Actual Results: As Expected
- Test Status – Pass/Fail: Pass
Once test cases have been shaped, corresponding tests must be run on real browsers, devices, and operating systems. Remember that device fragmentation is a significant concern for every developer and tester. Every website has to work seamlessly on multiple device-browser-OS combinations. With 9000+ distinct devices being used to access the internet globally, all software must be optimized for different configurations, viewports, and screen resolutions.
The Objective of Writing Test Cases in Software Testing
- To validate specific features and functions of the software.
- To guide testers through their day-to-day hands-on activity.
- To record a catalog of steps undertaken, which can be revisited in the event of a bug popping up.
- To provide a blueprint for future projects and testers so they don’t have to start work from scratch.
- To help detect usability issues and design gaps early on.
- To help new testers and devs quickly pick up testing, even if they join in the middle of an ongoing project.
How to Write Test Cases in Manual Testing with Template
How to write a test case?
Best Practice for writing good Test Case. Step 1) A simple test case to explain the scenario would be Step 2) Test the Data. In order to execute the test case, you would need Test Data. Adding it below Identifying test data can be time-consuming and may sometimes require creating test data afresh. The reason it needs to be documented.
How to write a manual test case?
If I explain to you in just a two-line summary of how to write a manual test case, it would be: 1. Identify the feature or functionality you wish to test. 2. Create a list of test cases that define specific actions to validate the functionality. Let’s see the detailed steps for writing test cases.
How should a software tester write a test case?
Manual testing of test cases should include steps to replicate actions performed in the software and validate that results are accurate and consistent. A systematic approach to writing test cases with strong input and output validations will help uncover issues easily, giving the tester a thorough view of any software product.
How do you write a test case summary?
For each test case, create a summary. This is a clear, simple description of what the test is. If you use a test case management solution, this will appear like a title in your overview of your tests. Make it easy to distinguish one from another. Step 3. Include a description of goals. Help the tester understand the big picture.