Quality Assurance·

How to Write Test Cases: Format, Examples and a Template for E2E Flows

How to write test cases that anyone, or any agent, can run: the format, a copyable template, login and checkout examples, and test case vs test scenario.

QA.tech

A rotary card file of blank frosted acrylic cards on a brass spindle, one card pulled forward, representing a set of written test cases.

A test case is a written check with a clear pass or fail: what you're trying to do, how to do it, and what should happen. A good one can be run by someone who has never seen the feature, a script or an AI agent, and they'd all reach the same verdict.

Most test cases go wrong in one of two ways. Some are so vague that nobody can say whether they passed. Others are so detailed that they break every time the UI changes. This guide is about the middle ground.

What a test case contains

Formal templates, such as the test case specification in ISO/IEC/IEEE 29119-3, list a dozen fields. For an end-to-end test, three of them do the work:

  1. Goal. What the user is trying to do, written as an action. "Reset a forgotten password", not "Password reset page".
  2. Expected result. What you can observe when it worked. "The user can log in with the new password and lands on the dashboard", not "Password reset works".
  3. Steps. How to get there. Optional for some tests, essential for others (more on that below).

Everything else is context that makes the test runnable:

  • ID and title, so people can refer to it.
  • Preconditions: the account, role, data or feature flags the test needs before step 1.
  • Test data: the specific values to use, such as the email, the card number or the product.
  • Priority, so you know what to run when time is short.
  • Postconditions or cleanup: what the test leaves behind and who removes it.

Test case template

Copy this and fill it in.

FieldWhat to writeExample
IDShort and uniqueAUTH-007
TitleGoal in a few wordsReset forgotten password by email
GoalThe user's action, in one sentenceReset a forgotten password using the email link
PreconditionsState before step 1Active account qa+reset@example.com exists; user is logged out
Test dataValues to useNew password Correct-Horse-42
StepsNumbered, one action each1. Open the login page. 2. Click "Forgot password". 3. Enter the account email and submit. 4. Open the reset email and follow the link. 5. Enter and confirm the new password. 6. Log in with the new password.
Expected resultWhat you can observe on successThe reset email arrives within 2 minutes; after step 6 the user lands on the dashboard; the old password no longer works
PriorityHigh, medium or lowHigh
CleanupWhat to reset afterwardsSet the password back, or use a fresh account per run

How to write a test case, step by step

  1. Start from a user story or a change. "As a user who forgot my password, I want to reset it by email." One user story usually maps to one test case. If it needs several, the story is probably doing too much.
  2. Write the goal as something a user does. Verbs, not page names.
  3. Write the expected result before the steps. It forces you to decide what "works" means. Make it observable: text on the screen, a record in the admin panel, an email in an inbox.
  4. List the preconditions. Every bit of state the test relies on. Most flaky test cases have a hidden precondition, such as "the cart is empty" or "this user has never logged in before".
  5. Write the steps at the right level of detail (next section).
  6. Keep it short. If a test case needs more than about ten steps, split it and make the second test depend on the first. "Create an account" and "Upgrade to a paid plan" are two test cases, with the second starting where the first ends.
  7. Have someone else run it. If they ask a question, the answer belongs in the test case.

How detailed should the steps be?

This is the decision that matters most, and the answer depends on the journey.

Daniel Mauno Pettersson, our co-founder and CEO, splits it this way. A test case is a goal and an expected result, with steps as an option. Write precise steps for journeys that must never change, such as a regulated onboarding flow where the order of screens is part of the requirement. Write high-level steps, or none, where you only care that the functionality works and the exact path can change.

Here's the same test at both levels.

Precise:

  1. On /login, click the "Forgot password?" link below the password field.
  2. Enter the email in the field labelled "Email address".
  3. Click "Send reset link".
  4. Check the confirmation message reads "Check your inbox".

High-level:

  1. Request a password reset for the account email from the login page.
  2. Follow the link in the email and set a new password.

The precise version fails if the link becomes a button or the message changes to "We've sent you an email". Sometimes that's what you want, because the copy was signed off by legal. Usually it isn't, and the high-level version tests the same thing with far less upkeep.

Test case examples

Test cases for a login page

The most searched example, so here's a fuller set. Each line is a test case title with its expected result.

IDTest caseExpected result
LOGIN-01Log in with a valid email and passwordLands on the dashboard; user's name shown in the header
LOGIN-02Log in with a wrong passwordError message shown; stays on login page; no session created
LOGIN-03Log in with an unregistered emailSame error as LOGIN-02, so the form doesn't reveal which emails exist
LOGIN-04Submit with empty fieldsValidation messages on both fields; no request sent
LOGIN-05Lock out after repeated wrong passwordsAfter the configured number of attempts, the account is locked and the user is told how to unlock it
LOGIN-06Log in with a one-time code from an authenticator appPrompted for the code after the password; valid code logs in; expired code is rejected
LOGIN-07Log in with a magic linkLink from the email logs in once; a second click on the same link is rejected
LOGIN-08Stay logged in after closing the browserWith "remember me" ticked, user is still logged in on return
LOGIN-09Log outSession ends; the back button doesn't show logged-in pages

LOGIN-06 and LOGIN-07 are where automated tests most often give up, because they need an inbox or an authenticator. How to E2E test login, 2FA and email verification covers how to automate them.

Test case for a checkout

FieldContent
GoalBuy one product as a guest with a discount code
PreconditionsProduct "Trail Runner" in stock in size 42; code SAVE10 active
StepsAdd the product in size 42 to the cart; apply SAVE10; check out as a guest with the test card
Expected resultOrder confirmation shows an order number and a 10% discount; order appears in the admin panel with size 42 and the discounted total

Note the expected result checks two places, the confirmation page and the admin panel. A checkout that shows a confirmation without creating the order is a real bug, and a test that only checks the page misses it.

Test case vs test scenario

A test scenario is what to test. A test case is how to test it.

Test scenarioTest case
LevelHigh: a feature or situationDetailed: one check with a verdict
Example"Users can recover a forgotten password"AUTH-007 above
ContainsA one-line descriptionGoal, preconditions, data, steps, expected result
How manyA few per featureSeveral per scenario

The scenario "users can recover a forgotten password" might become four test cases: reset by email, expired reset link, reset for an unregistered email, and reset while logged in on another device.

Common mistakes

  • No expected result, or one that can't be observed. "Works correctly" can't fail.
  • Several goals in one test case. When it fails, you don't know which one broke.
  • Hidden preconditions. The test passes for the author because their account already has data.
  • Steps tied to the layout. "Click the blue button in the top right" breaks on the next redesign.
  • Shared test data. Two tests using the same account will interfere when they run at the same time. See test data management for E2E tests.
  • Never deleting test cases. A test case for a feature that changed two years ago costs time on every run. We make the case for keeping the regression suite small in why a large regression suite is a liability.

Can ChatGPT or an AI write test cases?

Yes, and it's a good way to get a first draft. Give it the user story, the acceptance criteria and, if you can, the pull request description. It'll list the obvious cases quickly, including negative ones people forget. It won't know your preconditions, your test data or which journeys actually matter to your customers, so review the list before anyone runs it.

The bigger change is that test cases are increasingly written for agents to run, not only people. That changes what "good" means. An agent needs the same thing a new tester needs: a clear goal, an observable expected result, and steps only where the path matters. Our piece on writing acceptance criteria for agentic testers goes deeper.

Where QA.tech fits

QA.tech is an AI testing platform where test cases are written in exactly this shape: a goal, an expected result and optional steps. It runs web tests in Chromium only, and it doesn't replace thinking about what matters: a vague goal gives a vague verdict, whoever runs it.

It does take on the writing for each change. When a pull request opens, the agent reads the description first, then any linked Jira or Linear tickets, then the changed files and commits, and writes test cases for what the change could affect. It runs them against the preview deployment and reports on the pull request. After merge, the ones worth keeping are promoted to the regression suite. The rest stay labelled as ephemeral and get reused when a later pull request touches the same journey. For more on that split, see turning PR test cases into a regression suite.

FAQ

What is a test case? A test case is a written check with a goal, the conditions it needs, the steps to follow and the expected result. Anyone who runs it should reach the same pass or fail verdict.

What is the format of a test case? At minimum: ID, title, preconditions, test data, steps and expected result. Many teams add priority and cleanup. For end-to-end tests, the goal and the expected result matter most.

What is a test case template? A reusable table or form with the fields every test case should fill in, so all test cases in a team look the same. The template in this article is a good starting point.

What is the difference between a test case and a test scenario? A test scenario describes what to test at a high level, such as "users can reset their password". A test case is one detailed check within that scenario, with steps and an expected result.

What is the best way to write test cases? Start from a user story, write the expected result before the steps, list every precondition, keep it under about ten steps, and only write precise steps when the exact path matters.

How many test cases should one user story have? Usually one main test case for the happy path, plus a few for the failures that matter, such as wrong input or missing permissions. If one story needs many, consider splitting the story.

Can ChatGPT generate test cases? Yes. Given a user story and acceptance criteria, it produces a useful first draft, including negative cases. It doesn't know your test data, preconditions or priorities, so review the output before using it.

Your team moves fast. Can your testing keep up?

Our QA agents test your product autonomously, so moving fast never means shipping broken. Start free or get a 30-minute demo.