How to Write Test Cases: Structure, Test Design Techniques and Examples
A test case is only as good as its description. If it just says "check login", everyone tests something different, and a defect can hardly be reproduced later. Well-written test cases, on the other hand, are unambiguous, repeatable and can be automated when needed. This article shows how to write test cases: which structure has proven itself, which techniques help you find the right test cases and what matters in agile teams.
What is a test case?
A test case describes under which preconditions, with which inputs and in which steps a specific behaviour of the software is checked, and which result is expected. The decisive part is the expected result: only the comparison between expected and actual behaviour turns using the software into a test.
Test cases do not stand alone. Which areas are tested at all, and how thoroughly, is defined in the test strategy and the test plan. Test cases put these decisions into practice at the operational level.
Test case structure: the building blocks
Whether in Jira, a test management tool or a spreadsheet, a good test case always contains the same building blocks.
- ID and title: a unique identifier and a title that names the behaviour under test, such as "Login with a locked user account is rejected".
- Link to the requirement: a reference to the user story, requirement or acceptance criterion, so it stays traceable which requirements are covered.
- Preconditions: what must be in place before the test, for example a specific user, role or data state.
- Test data: concrete input values instead of "valid data".
- Test steps: numbered, short steps, one action per step.
- Expected result: precise and verifiable, per step where needed.
- Priority: derived from the risk of the area under test.
More fields are possible but rarely necessary. Every additional mandatory field costs time in maintenance, and fields that are only partly filled in confuse more than they help.
The test case describes what is to be checked. What actually happened during execution is recorded in the test log, with the actual result, status and evidence.
How to write test cases in five steps
1. Understand the requirement and clarify the test basis
Test cases are derived from requirements, user stories, process descriptions or interface specifications. Unclear or contradictory requirements surface particularly early when you write test cases. Clarify these questions before you continue. The article Clean requirements in IT projects explains why this matters so much.
2. Derive test conditions
First note what should be checked before deciding how. For a login, these could be: successful login, wrong password, locked account, lockout after several failed attempts, empty mandatory fields. This list quickly shows whether important cases are missing.
3. Apply test design techniques
For each test condition, choose suitable input values. Proven techniques for this are described in the next section. They help you find as many defects as possible with few test cases.
4. Write out the test case
Write preconditions, steps and expected results so that a knowledgeable person can test without asking questions. One action per step, concrete values, no room for interpretation.
5. Review and prioritise
Have test cases reviewed by a second person, ideally from the business side. Give each test case a priority based on risk, so that you know what to test first when time is short. The article Risk-based testing describes how.
Test design techniques: finding the right test cases
Testing every conceivable combination is practically never possible. Test design techniques help you systematically pick a small but meaningful selection.
- Equivalence partitioning: inputs that should behave the same are grouped into classes. One representative per class is enough.
- Boundary value analysis: defects often occur at the edges of value ranges, so the values directly at and next to each boundary are tested.
- Decision tables: when several conditions jointly determine a result, such as discount or tariff rules, a table makes all relevant combinations visible.
- State transition testing: for processes with a status, for example order created, approved, cancelled, you check allowed and disallowed transitions.
- Experience-based testing: knowledge of typical sources of defects complements the systematic techniques, such as special characters, empty inputs or concurrent editing.
Test case example with boundary value analysis
Suppose the requirement reads: "After three consecutive wrong password entries, the account is locked." The boundary is three failed attempts. Useful test cases therefore cover two, three and, as confirmation, four failed attempts. One of these test cases could look like this:
- Title: Account is locked after the third wrong password
- Requirement: story "Account lockout after failed attempts"
- Precondition: test user "test.customer" is active, failed-attempt counter is 0
- Steps: 1. Open the login page. 2. Log in as "test.customer" with a wrong password. 3. Repeat step 2 two more times. 4. Try to log in with the correct password.
- Expected result: after step 3, a message states that the account is locked. In step 4, the login is rejected despite the correct password.
- Priority: high (security-relevant)
The test case for two failed attempts checks the counterpart: after the second failed attempt, logging in with the correct password must still be possible.
What makes a good test case
- Unambiguous: two people execute the test case the same way and reach the same verdict.
- Independent: a test case does not assume that another one has run before. This makes prioritisation and automation easier.
- Focused: one test objective per test case. If it fails, it is immediately clear what does not work.
- Traceable: the link to the requirement is documented.
- Maintainable: recurring flows such as logging in are described as preconditions, not repeated in every test case.
Writing test cases in agile teams
In Scrum teams, test cases are not written in a separate phase but together with the user story. Acceptance criteria are the most important test basis. The Given-When-Then format has proven itself: "Given an active account, when a wrong password is entered three times, then the account is locked." Criteria written this way are equally clear to the business, developers and testers and can be turned directly into automated tests. The article Agile testing in Scrum shows how testing works within the sprint as a whole.
Agile does not mean undocumented. Test cases for critical flows that are checked before every release belong in a maintained regression test suite. Many of them are good candidates for test automation.
Common mistakes when writing test cases
- Missing or vague expected result: "works correctly" is not a verifiable result.
- Only the happy path is tested: invalid inputs, boundary values and cancellations often find the more important defects.
- Too much in one test case: long test cases with many objectives are hard to evaluate and maintain.
- Unclear test data: without concrete values, a test case cannot be repeated. How to make test data reliably available is covered in Test Data Management.
- No maintenance: test cases for changed functions are not updated and deliver wrong results.
Conclusion
Good test cases are not a form to fill in but the result of clear thinking: what should be checked, with which values, and how do you recognise success? If you derive test conditions carefully, use test design techniques and write every test case unambiguously, you find more defects with less effort and create a solid basis for regression testing and automation. If you want test cases written and executed manually by an external team, we do this as a software testing provider in Hamburg.
Frequently asked questions about writing test cases
How do you write a good test case?
A good test case has a meaningful title, a link to the requirement, clear preconditions, concrete test data, short numbered steps and a precise, verifiable expected result. It checks exactly one test objective and can be executed independently of other test cases.
What is the difference between a test case and a test scenario?
A test scenario roughly describes what should be checked, such as "customer orders as a guest". A test case makes this concrete with preconditions, test data, steps and an expected result. One test scenario usually leads to several test cases.
How many test cases does a requirement need?
That depends on risk and complexity. Every requirement should have at least one test case for the happy path; invalid inputs, boundary values and special cases are added depending on their importance. Test design techniques such as equivalence partitioning and boundary value analysis keep the number manageable.
Test cases and test strategy from one source
30-minute initial consultation — free and without obligation. We look at your test cases together and show how to find more defects with less effort.
Book a Free Initial ConsultationMore about our service: Software testing, test management & QA in Hamburg →