How to Write Test Cases: Format, Examples and Best Practices
A good test case is clear enough that anyone on the team can run it and get the same result. Learn the format, see real examples and copy a simple template.
- A test case is a set of steps, data and expected results that checks one specific behaviour.
- Use a fixed format: ID, title, preconditions, steps, test data, expected result and status.
- Write one test case per behaviour, and cover positive, negative and boundary inputs.
- Clear, short test cases are easy to review and easy to automate later.
Every tester gets asked the same thing at some point: can you write test cases for this feature? If you are new, it is hard to know how to write test cases with the right level of detail, or where to start.
Knowing how to write test cases well saves time for the whole team. Good ones find bugs earlier, make regression runs repeatable and let a new colleague run your tests without asking questions.
This guide shows how to write test cases step by step, with a standard format, a login and a checkout example, a template you can copy and best practices used by QA teams.
What is a test case?
A test case is a documented check for one behaviour of the software. It states what to do, what data to use and what result to expect. The ISTQB glossary defines it as a set of preconditions, inputs, actions and expected results developed for a particular objective.
A test scenario is a high-level idea such as “user can log in”. A test case is a specific, runnable check under that scenario, such as “login fails with a wrong password”.
Standard test case format
Most teams use the same fields, whether they work in a spreadsheet or a test management tool.
| Field | Purpose |
|---|---|
| Test case ID | Unique reference, for example TC_LOGIN_001 |
| Title | One line saying what is verified |
| Preconditions | State needed before starting (user exists, browser open) |
| Steps | Numbered actions in order |
| Test data | Exact inputs to use |
| Expected result | What should happen if the software is correct |
| Actual result | What happened during the run |
| Status | Pass, fail, blocked or not run |
| Priority | High, medium or low |
How to write test cases step by step
- Understand the requirement. Read the user story or spec and list the rules. Ask about anything unclear before you write a line.
- List scenarios. Think about the happy path, error paths and edge cases.
- Pick one behaviour per test case. If a title needs “and”, split it in two.
- Write preconditions and test data. Use specific values, not “valid email”.
- Write short, numbered steps using plain verbs: open, enter, click, select.
- State a precise expected result. “Error message ‘Invalid password’ appears” beats “error shown”.
- Review with a developer or peer to catch missing cases and wrong assumptions.
Test case examples
Example 1: login with valid credentials
| Field | Value |
|---|---|
| ID | TC_LOGIN_001 |
| Title | Registered user logs in with valid credentials |
| Preconditions | Account user@example.com exists and is active |
| Steps | 1. Open the login page. 2. Enter the email. 3. Enter the password. 4. Click Log in. |
| Test data | Email: user@example.com, Password: Secret123 |
| Expected result | User lands on the dashboard and sees their name in the header |
Example 2: login with a wrong password
| Field | Value |
|---|---|
| ID | TC_LOGIN_002 |
| Title | Login fails with an incorrect password |
| Steps | 1. Open the login page. 2. Enter a valid email. 3. Enter a wrong password. 4. Click Log in. |
| Expected result | User stays on the login page and sees “Invalid email or password”; no session is created |
Example 3: checkout with an expired coupon
Preconditions: cart has one item and coupon SAVE10 expired yesterday. Steps: open the cart, enter SAVE10, click Apply. Expected result: a message says the coupon has expired and the cart total does not change.
Positive, negative and boundary test cases
When you plan how to write test cases for a feature, cover three groups:
- Positive: valid input produces the expected outcome.
- Negative: invalid, empty or malicious input is rejected safely.
- Boundary: values at the edge of a range, such as a password of exactly 8 characters when the minimum is 8.
For a field that accepts ages 18 to 60, test 17, 18, 60 and 61, plus an empty value and text such as “abc”.
Best practices for writing test cases
- Keep each test case independent, so one failure does not block the others.
- Use clear, consistent names so people can search and filter.
- Avoid vague words such as “properly” or “correctly” in expected results.
- Do not repeat steps that belong in preconditions.
- Link every test case to a requirement or user story for traceability.
- Review and retire outdated cases every sprint.
- Mark high-risk and frequently used flows as high priority and automate them first.
Quick tip: Ask yourself, “could a new teammate run this test without asking me anything?” If not, add detail. Also see how smoke testing vs sanity testing decides which cases to run first.
From manual test cases to automation
A well-written manual case becomes an automated test almost line by line. Here is TC_LOGIN_001 as a Playwright test (see the Playwright guide to writing tests):
import { test, expect } from '@playwright/test';
test('TC_LOGIN_001: registered user logs in', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Email').fill('user@example.com');
await page.getByLabel('Password').fill('Secret123');
await page.getByRole('button', { name: 'Log in' }).click();
await expect(page).toHaveURL(/dashboard/);
});
Start by automating stable, high-value cases. Our guides on test automation tools, end to end testing best practices and API testing with Postman show where to go next.
Final thoughts
Learning how to write test cases is mostly about clarity: one behaviour, exact data and a precise expected result. Use the format above, cover positive, negative and boundary inputs, and get a peer review. Start with the template for your next story and refine it as your team learns what works.
Frequently asked questions
What are the main parts of a test case?
An ID, title, preconditions, steps, test data, expected result, actual result and status. Many teams also add priority and a link to the requirement.
How many test cases should I write per feature?
There is no fixed number. Cover the happy path, important error paths and boundary values, and add more for high-risk areas.
What is the difference between a test case and a test scenario?
A scenario is a high-level situation to verify, while a test case is a detailed set of steps, data and expected results for one specific check.
Can I write test cases without documentation?
Yes, but ask questions first. Talk to the product owner or developer, explore the feature and record assumptions so the cases can be reviewed.
Should every test case be automated?
No. Automate stable, repetitive and high-value cases. Keep exploratory and one-off checks manual.
Keep learning
Need help with testing, WordPress or SEO?
We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.