Back To Blogs

How to Write Test Cases (With Templates and Examples)

A test case is a set of conditions and steps that checks one specific behaviour of the software. Good test cases are clear enough that anyone on the team can run them and get the same result, and focused enough that a failure points straight at the problem.

When to write test cases (and when not to)

Detailed test cases are worth the effort when:

  • The flow is business-critical (payments, sign-up, data export)
  • The test will be run many times (regression) or automated later
  • You need evidence for audits or compliance
  • Someone new will run the tests

For fast-moving features, a checklist or an exploratory charter is often a better use of time. Don't write 40 detailed cases for a page that will change next sprint.

The fields that matter

FieldPurpose
IDA unique reference, e.g. LOGIN-004
TitleWhat is being verified, in one line
PreconditionsState before the test: user exists, cart is empty, feature flag on
Test dataThe exact inputs
StepsNumbered actions
Expected resultThe observable outcome that means "pass"
PriorityHow important this case is in a regression run

Optional fields (requirement link, automation status, component) help at scale but aren't essential.

Template

**ID:** AREA-000
**Title:** Verify that …
**Preconditions:**
**Test data:**
**Steps:**
1.
2.
**Expected result:**
**Priority:** High | Medium | Low

Examples: a login form

LOGIN-001: Valid credentials sign the user in

  • Preconditions: a verified account [email protected] exists
  • Test data: email [email protected], the correct password
  • Steps: 1. Open /signin 2. Enter the email and password 3. Click "Sign in"
  • Expected: The user lands on the dashboard and their name appears in the header
  • Priority: High

LOGIN-002: Wrong password shows a generic error

  • Test data: a correct email and a wrong password
  • Expected: "Invalid email or password" is shown. The message doesn't reveal whether the email exists. The password field is cleared.
  • Priority: High

LOGIN-003: The email is matched case-insensitively

  • Test data: [email protected] with the correct password
  • Expected: The user is signed in
  • Priority: Medium

LOGIN-004: Repeated failures are rate limited

  • Steps: Submit a wrong password 10 times within one minute
  • Expected: Further attempts are blocked for a period, with a clear message
  • Priority: Medium

Notice that each case checks one behaviour, with specific data and a verifiable expected result.

Writing tips

  1. Start titles with "Verify that…" or state the behaviour. It forces you to name what's being checked.
  2. One expected outcome per case. If you write "and also…", consider splitting it.
  3. Make expected results observable. "Works correctly" can't be checked; "the order appears in Order history with status Paid" can.
  4. Keep steps at the user's level. Use "Add the mug to the cart", not "Click div.product-card:nth-child(3) button".
  5. Separate data from steps. Then the same case can run with several data sets.
  6. Cover negative paths. For every "it accepts X", ask "what does it do with not-X?"

Using design techniques to choose cases

Don't write test cases at random. Use techniques like boundary value analysis and equivalence partitioning for inputs, decision tables for combinations of rules, and state transitions for flows like orders and bookings. The technique tells you which cases you need; the template tells you how to write them down.

Keeping a suite healthy

  • Review and prune it every few releases; delete cases for removed features
  • Tag cases by area and priority so you can run a focused regression
  • Automate the stable, high-value, repetitive cases first
  • When a bug escapes to production, add the missing case

Practise test design

Writing test cases is easier once you've seen where real bugs hide. Try a QAUnlocked Practice Lab, then write the test cases that would have caught every planted defect. It's a great portfolio piece, too.

test casestest designdocumentationtemplates

Comments

0 Comments

Be the first to comment.