Test cases in software testing: template, examples and design techniques

What a test case is, a template to copy, worked examples for login, payments and uploads, and the design techniques testers use to pick cases.
Back to blog

Test cases in software testing: template, examples and design techniques

Short answer

A test case is a written check of one specific behaviour of your software. It lists the starting conditions, the exact steps, the test data and the result you expect. Someone runs the steps, compares what happened with what was expected, and marks the test passed or failed. A failed test case is the start of a bug report.

This guide covers what goes into a test case, a template you can copy, three worked examples, the difference between a test case and a test scenario, and the design techniques testers use to decide which cases to write. It is written from how our engineers write and maintain test cases on client projects every day.

A BetterQA engineer in a teal sweater working at her monitor in the Cluj-Napoca office
Article details
Question
What is a test case, and how do you write a good one?
Audience
Testers, developers and team leads who write or review tests
BetterQA team
50+ engineers, founded 2018
Clutch rating
4.9 / 5 from 71 reviews

The parts of a test case

Teams and tools name the fields differently, but a usable test case always answers the same questions: what are we checking, what must be true before we start, what exactly do we do, with which data, and what should happen. Everything else is there to make the case findable, traceable and easy to report on.

FieldWhat it holdsWhy it matters
IDA unique reference, such as TC-LOGIN-004Bug reports, results and requirements can point at it
TitleOne line saying what is checkedSomeone scanning a list knows what the case is for without opening it
RequirementThe user story or requirement it coversShows which requirements are tested and which are not
PreconditionsWhat must be true before step 1: account state, data, environmentMost "cannot reproduce" arguments start with a missing precondition
Test dataThe exact values to use"Enter a valid email" gives ten testers ten different tests
StepsNumbered actions, one action per stepAnyone on the team can run it the same way
Expected resultWhat the software should do, stated so it can be checkedWithout it there is no pass or fail, only an opinion
Actual resultWhat happened when the case was runThe evidence behind a pass, and the first line of a bug report
StatusPassed, failed, blocked or not runFeeds the release decision
PriorityHow much the case matters if time runs outTells the team what to run first before a release

The expected result is the field people most often get wrong. "Login works" cannot fail. "The user lands on /dashboard within 2 seconds and sees their name in the header" can. We wrote a separate guide on writing expected results because the same rule decides whether a bug report is useful.

A test case template you can copy

This is the layout our engineers start from when a client has no test management tool yet. It works in a spreadsheet, a Jira issue or a test management tool, because every tool has the same fields under different names.

FieldYour entry
IDTC-[AREA]-[NUMBER]
Title[Feature] [does what] when [condition]
Requirement[Story or requirement ID]
PriorityHigh / Medium / Low
Preconditions[Account, data and environment state before step 1]
Test data[Exact values]
Steps1. [One action] 2. [One action] 3. [One action]
Expected result[What the user sees or the system records, specific enough to fail]
Actual result[Filled in when run]
StatusPassed / Failed / Blocked / Not run

Write the title so it reads as a sentence about behaviour: "Login rejects a wrong password and keeps the email filled in" tells a reviewer far more than "Login test 4".

BugBoard test case view with preconditions, numbered steps and expected results for a checkout flow
A test case in BugBoard: preconditions, steps and expected result (demo data)

Three test case examples

Example 1: login with a wrong password

IDTC-LOGIN-004
TitleLogin rejects a wrong password and keeps the email filled in
PreconditionsAn active account exists for anna@example.com. The user is logged out.
Test dataEmail: anna@example.com. Password: WrongPass1
Steps1. Open /login. 2. Enter the email. 3. Enter the password. 4. Click "Log in".
Expected resultThe user stays on /login. The message "Email or password is incorrect" appears under the form. The email field still shows anna@example.com and the password field is empty. No session cookie is set.

Note what the expected result does not say: it does not reveal whether the email or the password was wrong. Telling an attacker which accounts exist is a security defect, so a good test case checks the wording as well as the redirect.

Example 2: card payment declined

IDTC-PAY-012
TitleCheckout shows a clear message and keeps the order when the card is declined
PreconditionsPayment provider in test mode. Cart contains one item at 49.00 EUR.
Test dataThe provider's published test card number for "card declined"
Steps1. Go to checkout. 2. Enter the test card. 3. Click "Pay".
Expected resultThe page says the payment was declined and offers another card. The order is saved as "payment failed", not "paid". No confirmation email is sent. The cart still contains the item.

Payment cases are where we see the most expensive misses, because the screen can look right while the order status underneath is wrong. Our guide to testing card types lists the scenarios worth covering.

Example 3: file upload over the size limit

IDTC-UPLOAD-007
TitleUpload refuses a file just over the 10 MB limit with a message
PreconditionsLogged in as a user with upload rights. Limit configured at 10 MB.
Test dataA PDF of 10.1 MB
Steps1. Open the documents page. 2. Click "Upload". 3. Choose the file.
Expected resultThe upload is refused before it finishes. The message names the 10 MB limit. Nothing is stored on the server.

The 10.1 MB file is chosen on purpose: it sits just past the limit, which is where size checks break. The section on boundary value analysis below explains why. For the full set of upload checks, see our file upload testing cheat sheet.

Test case vs test scenario vs test script

The three words get mixed up constantly. The difference is how much detail each one carries.

Test scenarioTest caseTest script
What it isA situation worth testingExact steps, data and expected result for one checkCode that runs a test case automatically
Example"User logs in with wrong details"TC-LOGIN-004 aboveA Playwright or Cypress test that performs TC-LOGIN-004
DetailOne lineA full page of steps and dataExecutable code
Written byTester or analyst, earlyTesterAutomation engineer
How manyOne scenario usually becomes several casesSeveral per scenarioOne per automated case

A practical order: list the scenarios first so nothing obvious is missed, write test cases for the scenarios that carry the most risk, then automate the cases you will run on every release.

Types of test cases

Most projects need a mix. The list below is the set we plan for on a typical web or mobile product.

  • Functional: does the feature do what the requirement says.
  • Negative: does it handle wrong input, missing data and unexpected actions without breaking. See positive and negative testing.
  • Boundary: does it behave at the edges of allowed values.
  • Regression: does existing behaviour still work after a change. See how to choose what to run.
  • Integration: do two parts, or your product and a third-party service, work together.
  • UI and usability: can a person actually complete the task.
  • Accessibility: can people using a keyboard or a screen reader complete it.
  • Performance: does it stay fast under realistic load.
  • Security: can it be misused, for example by reading another user's data.
  • User acceptance: does the business owner agree it does the job.

Test case design techniques, with examples

Design techniques answer the hard question: out of the endless inputs a feature accepts, which few do you actually test? The ISTQB Foundation syllabus (CTFL 4.0.1, chapter 4) groups them into three families: black-box, white-box and experience-based. It adds collaboration-based approaches as a separate topic. Most of the cases we write come from the first family.

Specification-based (black box) techniques

These work from the requirement alone, without looking at the code.

Equivalence partitioning. Split the inputs into groups the software should treat the same way, then test one value from each group. If a form accepts ages 18 to 65, there are three groups: under 18, 18 to 65, and over 65. Three test cases, with ages 12, 40 and 70, cover what three hundred would.

Boundary value analysis. Bugs collect at the edges, where a developer typed < instead of <=. For the same age field, test 17, 18, 65 and 66: the last value outside, the first value inside, the last value inside, the first value outside again. This is the technique behind the 10.1 MB file in example 3. Testing each boundary value and its closest neighbour in the next partition, as done here, is called two-value boundary value analysis. The syllabus also describes a three-value version, which tests each boundary value and both of its neighbours: 17, 18 and 19, then 64, 65 and 66.

Decision table testing. When the result depends on several conditions together, list every combination in a table so none is forgotten. A discount rule shows why:

Rule1234
Customer is a memberYesYesNoNo
Order over 100 EURYesNoYesNo
Expected discount15%10%5%None

Each column becomes one test case. Teams that test only the first and last column miss the two middle rules, which is where conditions usually get combined wrongly in code.

State transition testing. For anything that moves between states, test the transitions, including the ones that should be impossible. An account that locks after three failed logins has the states active, locked and unlocked. Test cases cover the third failure locking the account, a correct password not unlocking a locked account, and the unlock link restoring access.

Use case testing. Follow a complete user journey end to end, such as "a new customer signs up, buys, and receives an invoice", to catch problems that only appear when the steps run in sequence. Use case testing was a named technique in older Foundation syllabi. CTFL 4.0.1 no longer lists it among the black-box techniques and it is now covered at Advanced Level (Test Analyst) under scenario-based testing, but it remains a useful way to write end-to-end cases.

Structure-based (white box) techniques

These look at the code and measure how much of it the tests exercise. Statement coverage asks whether every executable statement ran at least once. Branch coverage asks whether every branch was taken, including both outcomes of each decision, the "if" and the "else". Any set of tests that reaches 100% branch coverage also reaches 100% statement coverage, but not the other way round, and neither proves the code is free of defects. They are mostly used by developers in unit tests, and they are good at showing what was never tested, not at proving what works.

Experience-based techniques

Error guessing uses what a tester has seen break before: empty fields, pasted text with trailing spaces, a double click on "Pay", a session that expired mid-form. Exploratory testing is structured investigation without a script, with notes, which often finds the cases nobody thought to write down. Checklist-based testing turns those lessons into a reusable list. The syllabus also covers collaboration-based approaches, which aim to prevent defects through conversation: writing user stories together, agreeing acceptance criteria, and acceptance test-driven development (ATDD).

In practice we combine them: partitions and boundaries for inputs, decision tables for business rules, state transitions for workflows, and a timeboxed exploratory session on every new feature to catch what the specification missed. Our test techniques service page describes how we apply them on client projects.

How to write a good test case

  1. Check one behaviour per case. If a case can fail for two different reasons, split it, or the failure will not tell you what broke.
  2. Make the expected result able to fail. Name the page, the message, the value or the record.
  3. Give exact test data. Values, not descriptions of values.
  4. State every precondition. Account type, feature flags, data that must already exist.
  5. Keep cases independent. A case that only passes after another case has run will fail for the wrong reason the day the order changes.
  6. Write for someone new. A tester who joined last week should be able to run it without asking.
  7. Link each case to a requirement. That is how you see which requirements have no tests.
  8. Retire what no longer applies. An outdated case that fails every run teaches the team to ignore failures.

We collected the mistakes we see most in reviews in common mistakes to avoid in test cases.

How many test cases do you need?

There is no correct number per feature, and a high count is not a sign of good coverage. What matters is that the risky behaviour is covered. We decide in three passes: list the scenarios for the feature, rank them by how much damage a failure would do and how likely it is, then write cases for the top of the list using the techniques above, and stop when the next case would only repeat a partition or boundary already tested.

A login form usually needs between ten and twenty cases once you count wrong passwords, locked accounts, expired sessions and password reset. A payment flow needs more, because each payment method and failure has its own path. Your test plan is the place to write down what is in scope and what is deliberately left out.

Where to keep test cases

A spreadsheet is fine for the first few dozen cases. After that, teams move to a test management tool so they can track runs, link cases to requirements and bugs, and see results per release. Common choices are Jira with a test add-on, TestRail and Azure DevOps Test Plans. We built our own, BugBoard, and we also work in whatever tool a client already uses.

Whichever tool you choose, keep the cases where your team can still read them if the tool or the vendor changes. Software can now draft a first version of test cases from a requirement in seconds, and we use that, but a person still reviews every case before it counts. Our article on generating test cases with a human review explains where drafts go wrong.

Frequently asked questions

A test case is a written check of one behaviour of the software: the preconditions, the steps, the test data and the expected result. Running it and comparing the actual result with the expected one tells you whether that behaviour works.
At minimum an ID, a title, preconditions, test data, numbered steps and an expected result. Most teams also record the linked requirement, priority, actual result and status.
A test scenario is a one-line situation worth testing, such as "user logs in with wrong details". A test case is the detailed check for one version of that situation, with exact steps, data and the expected result. One scenario usually produces several test cases.
Equivalence partitioning, boundary value analysis, decision table testing and state transition testing work from the requirements (use case testing is a similar scenario-based approach, no longer in the Foundation syllabus). Statement and branch coverage work from the code. Error guessing, exploratory testing and checklists work from the tester's experience.
Enough to cover each partition, each boundary and each rule combination that carries real risk. For a simple field that can be three or four; for a payment flow it can be several dozen. Stop when the next case would only repeat something already tested.
No. Automate the cases you run on every release and that are stable, such as login, checkout and core workflows. Keep manual or exploratory testing for new features, visual checks and anything that changes often, where a script would cost more to maintain than it saves.

Want test cases written and kept up to date for you?

Our engineers write, run and maintain test cases in your own tools, so the work stays with you. The first month is a trial on your product. If you are not happy, the first two weeks are complimentary.

Book a call Managed testing services
Share the Post: