Guide
How to write effective test cases
A good test case lets someone who didn't write it run it, get the same result, and know without debate whether it passed. These are the rules that get you there, a before-and-after example, and a template you can copy.
Open the test case generatorSix rules that matter
- Test one behaviour. The title names the behaviour and the condition: “Reject a quantity above 50”, not “Check order creation”. If a test can fail for two unrelated reasons, split it.
- Make preconditions support the expected result. “No results found” is only a valid expectation if the precondition guarantees no record matches. State the data that makes the outcome true.
- Use concrete test data. Write
quantity = 51, not “an invalid quantity”. Take boundaries from the requirement (limit, limit + 1), not from habit. - Write expected results you can check. “Works correctly” can't fail. “Status is 400 and the body contains
quantity_out_of_range” can. - Trace each test to its source. Reference the acceptance criterion or ticket, so coverage gaps are visible and outdated tests are easy to find when a requirement changes.
- Mark what you assumed. If the requirement doesn't say, don't invent an expected result silently: write it down as an assumption or an open question for the product owner.
Example: before and after
Requirement: “Search ignores case. Partial names match from the start of the first or last name.”
Before
Title: Test search. Steps: Search for a contact. Expected: Search works.
Nobody can tell which contact, what to type, or what “works” means, and it mixes case handling with partial matching.
After
- Preconditions:
- The signed-in user can see the contact Sara Ahmadi. No other visible contact has a first or last name starting with "ahm".
- Test data:
- Search text: ahm
- Basis:
- Documented (search rules 1 and 2)
| # | Action | Expected result |
|---|---|---|
| 1 | Type ahm in the search box and wait for the results to update. | Exactly one result is shown: Sara Ahmadi. |
| 2 | Clear the search box. | The full contact list is shown again. |
The precondition rules out other matches, so “exactly one result” is a fair expectation. Case handling for upper case gets its own test instead of being folded into this one.
Reusable template
Copy it into your test management tool, a spreadsheet or a Markdown file.
Test case template
ID: TC-___
Title: <behaviour under test> when <condition>
Requirement: <story / AC / ticket ID>
Priority: High | Medium | Low
Preconditions: <state that must be true before step 1, including data that
makes the expected result possible>
Test data: <exact values: inputs, accounts, IDs>
Steps:
1. Action: <one user or system action>
Expected: <observable result you can mark pass or fail>
2. Action: ...
Expected: ...
Basis: Documented | Assumption (<what was assumed>) | Exploratory
Open question: <anything the requirement doesn't answer; leave empty if none>Checklist before you hand tests over
- Every acceptance criterion has at least one test, and every test references one.
- Each limit or format in the requirement has a boundary test on both sides.
- No expected result states something the requirement doesn't say, unless it is marked as an assumption.
- No two tests check the same rule with cosmetic differences.
- Open questions are sent to whoever owns the requirement, not answered by guesswork.
Testfolio applies the same structure when it drafts tests from your requirements: preconditions, test data, steps with expected results, a basis on each test, and open questions where the input is unclear. See getting useful results for how to write input that leads to precise tests.
Try it with your own requirements
Browsing and sample results need no account. Generating tests needs a sign-in and uses credits; editing and exports are free.
Open the test case generator