How to Write Test Cases
How to Write Test Cases
Writing test cases is a crucial activity in the software testing lifecycle. A well-written test case ensures the quality of the application by validating that every feature works as intended. In this guide, we’ll explain how to write effective test cases step by step.
In this tutorial, you will learn how to write Test Cases for an application. Test cases should cover major functionality of the application and cover other non-functional aspects as well.
What is a Test Case?
A test case is a documented set of conditions, steps, and expected results used to determine whether a software application functions correctly.
Field | Description |
---|---|
Test Case ID | Unique identifier for the test case (e.g., TC_LOGIN_001) |
Test Case Title | Brief, descriptive title of the test case |
Description | Detailed explanation of what the test case will verify |
Pre-Conditions | Conditions that must be met before executing the test |
Test Steps | Step-by-step actions to perform during the test |
Test Data | Input data required to execute the test case |
Expected Result | The outcome that should occur if the test passes |
Actual Result | The real outcome observed after executing the test |
Status | Indicates whether the test passed or failed |
Remarks | Any additional comments or notes |
Steps to Write a Good Test Case
-
Understand Requirements
-
Read the requirement documents (BRD, SRS, user stories).
-
Ask clarifying questions if requirements are unclear.
-
-
Define Test Scenarios
-
Identify what needs to be tested (e.g., login, form validation).
-
-
Break Down Scenarios into Test Cases
-
One scenario can have multiple test cases (e.g., valid login, invalid login, empty fields).
-
-
Use Clear and Concise Language
-
Be precise and avoid ambiguous terms.
-
-
Keep it Reusable
-
Avoid hardcoding data; use placeholders if needed.
-
-
Include Edge Cases and Negative Testing
-
Test what happens with incorrect input, large values, etc.
-
Write Test Cases
Identify the main actors and the main functionality of the application in-order to document the test cases.
Ask yourself some questions like:
- Who is going to use the System?
- What is the main intended purpose of the application for the user?
- What are the Business Goals?
- Why would the user use the System? ( Business Value)
Divide the test cases into different categories like:
Functional Test cases
- Black-box testcases( Testing without knowing the inner details of the application under test)
- White-box testcases( What’s inside the box ? Source Code perspective testcases for example JUnit testcases)
- Integration testcases( co-existence with other systems, communication with other modules or systems)
- Usability testcases( How usable is the system? System settings, Themes, GUI , Look and Feel, Ease of Use, etc)
Non Functional Test cases
- Stress testcases ( How does the system behave under stress? Inject Low memory faults, sandbox the app in low resources, etc )
- Performance testcases ( How does the system perform under abnormal conditions. Create concurrent virtual sessions, measure response times, SLAs)
- Security testcases ( How secure is the system? Inject Security Threats, etc )
Example Test Case
Test Case ID: TC_LOGIN_001
Title: Valid Login
Description: Verify that a user can log in with valid credentials
Pre-conditions: User must be registered
Test Steps:
1. Open the login page
2. Enter valid username
3. Enter valid password
4. Click on "Login" button
Test Data:
Username: testuser
Password: Test@123
Expected Result: User is redirected to the dashboard
Actual Result: (Filled after execution)
Status: Pass/Fail
Remarks: -