Key takeaways
- A good test case is clear enough that someone else can run it and reach the same verdict without asking you.
- Each test case checks one thing, with concrete data and a specific expected result.
- Write only as much detail as your team needs. Clear beats long.
What a test case is for
A test case is a precise description of one check. It lets a colleague, a new team member or future you run the same test and know whether it passed.
If two people can run your test case and disagree about the result, it isn't finished.
The parts of a test case
| Part | What to write | Example |
|---|---|---|
| ID | A unique reference | TC-017 |
| Title | What's checked, in one line | Login fails with a wrong password |
| Preconditions | What must be true before starting | User ana@example.com exists with password Correct#123 |
| Steps | Numbered actions, one per line | 1. Open the login page. 2. Enter … |
| Test data | Exact values | Email ana@example.com, password Wrong#123 |
| Expected result | What should happen, precisely | Error "Email or password is incorrect"; user stays on login page |
| Link | The requirement or story it checks | Story LOGIN-4 |
Many teams also add priority (how important the test is) and postconditions (how to clean up afterwards).
Before and after
Before:
Title: Test login
Steps: Try logging in with wrong details.
Expected: It doesn't work.
What are "wrong details"? A wrong email, a wrong password, both? What does "doesn't work" look like: an error, a crash, a blank page?
After:
TC-017: Login fails with a wrong password
Preconditions: User
ana@example.comexists, with passwordCorrect#123. The user is logged out.Steps:
- Open the login page.
- Enter email
ana@example.com.- Enter password
Wrong#123.- Click Log in.
Expected: The message "Email or password is incorrect" appears. The user stays on the login page. The password field is empty.
Lesson: the second version takes a minute longer to write. In return, anyone can run it, and everyone agrees whether it passed.
Seven habits of good test cases
- One purpose per test case. "Login fails with wrong password" and "Account locks after 5 failed attempts" are two test cases, not one.
- A title that says what's checked. Someone scanning a list of 200 tests should understand each one from its title.
- Concrete data. Not "a valid email", but
ana@example.com. Not "a large amount", but10,000.00. - A specific, observable expected result. Exact messages, values and states. "Works correctly" isn't a result.
- Independent. Each test sets up what it needs, instead of relying on another test having run first.
- Traceable. Link it to the requirement or story it checks. When the requirement changes, you'll know which tests to update.
- Written for the reader. Use the product's real names for buttons and pages. Skip obvious steps like "turn on the computer".
Do
Write the expected result before running the test, based on the requirement. Then compare it with what actually happens.
Don't
Run the test first and write down whatever happened as the "expected result". You'll turn bugs into expected behaviour.
How much detail?
It depends on who'll use the test case.
- Regulated industries (medical, banking, aviation) often need very detailed test cases as evidence for audits.
- Small Agile teams may use short checklists: "Wrong password shows error, field cleared". That works when everyone knows the product well.
- Tests that will be automated need precise steps and data, because code can't guess.
Check yourself
A test case's expected result says: 'The order is processed correctly.' What's wrong with it, and how would you fix it?
Show answer
It's not specific or observable. Two testers could disagree about what "correctly" means. A better version: "The confirmation page shows order number, total 149.90, and status Paid. A confirmation email arrives at ana@example.com. Stock for the product decreases by 1."
