1. Home
  2. Blog
  3. Software Testing

Software Testing

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.

8 min read
How to write test cases: format, examples and best practices for QA

Key takeaways

  • 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

  1. Understand the requirement. Read the user story or spec and list the rules. Ask about anything unclear before you write a line.
  2. List scenarios. Think about the happy path, error paths and edge cases.
  3. Pick one behaviour per test case. If a title needs “and”, split it in two.
  4. Write preconditions and test data. Use specific values, not “valid email”.
  5. Write short, numbered steps using plain verbs: open, enter, click, select.
  6. State a precise expected result. “Error message ‘Invalid password’ appears” beats “error shown”.
  7. 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

Work with Stack Quora

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.

Keep reading

More guides on testing, AI & modern development

Enjoyed this article? Pick a topic and jump straight into our newest tutorials.

Databases & SQL

SQL GROUP BY and HAVING Explained With Examples

SQL GROUP BY and HAVING explained with sample tables, aggregate functions, WHERE vs HAVING and common mistakes, with queries you…

Read article →
Software Development

HTTP Status Codes Cheat Sheet for Developers and Testers

An HTTP status codes cheat sheet for developers and testers: every common 1xx to 5xx code, what it means and…

Read article →
Test Automation

Selenium WebDriver Waits Explained: Implicit, Explicit and Fluent

Selenium waits explained: implicit, explicit and fluent waits with Python examples, when to use each and how to remove flaky…

Read article →
Software Testing

Test Automation Mistakes Beginners Make and How to Avoid Them

The 10 test automation mistakes beginners make, from flaky waits to automating everything, and the practical fixes that keep your…

Read article →
Artificial Intelligence

Claude Opus 5.5 vs Sonnet 5.5: Pricing, Speed and When to Use Each

Claude Opus 5.5 vs Sonnet 5.5 compared: listed pricing, context, speed and a simple guide to which model fits coding,…

Read article →
Artificial Intelligence

Best AI Code Review Tools for Developers in 2026

Compare the best AI code review tools in 2026: CodeRabbit, GitHub Copilot, Qodo, Greptile and more. See what each does,…

Read article →
Software Development

What Is an API? A Simple Guide for Beginners

What is an API? Learn in plain English how APIs work, the main types, HTTP methods and status codes, with…

Read article →
Test Automation

Playwright Locators Cheat Sheet With Examples

A practical Playwright locators cheat sheet: getByRole, getByText, getByLabel, test IDs, CSS, filtering and chaining, with copy-paste examples for stable…

Read article →
Software Testing

How to Write Test Cases: Format, Examples and Best Practices

Learn how to write test cases with a clear format, login and checkout examples, a reusable template and best practices…

Read article →
Artificial Intelligence

Gemini 4 Argon: What’s New and How It Compares to Earlier Gemini Models

Gemini 4 Argon is Google's new flagship reasoning model. See its API limits, app features, coding focus and how to…

Read article →
Databases & SQL

SQL Joins Explained With Examples (Inner, Left, Right, Full)

SQL joins explained step by step with sample tables and queries: INNER, LEFT, RIGHT, FULL, CROSS and SELF joins, plus…

Read article →
Software Development

Python Virtual Environment Tutorial: venv, pip and uv

Learn how to create, activate and manage a Python virtual environment with venv, pip and uv, including requirements files, .gitignore…

Read article →
Test Automation

Playwright vs Cypress in 2026: Which Should You Pick?

Playwright vs Cypress compared for 2026: browsers, languages, speed, debugging, parallel runs, CI and cost. Find out which end-to-end testing…

Read article →
Software Testing

Smoke Testing vs Sanity Testing: Differences With Real Examples

Smoke testing checks that a build is stable enough to test. Sanity testing checks that a specific fix works. Learn…

Read article →
Artificial Intelligence

Claude Haiku 5.5: Features, Pricing and Use Cases for Developers

Claude Haiku 5.5 is Anthropic's fastest and lowest-priced model. See its 1M-token context, pricing, API changes and the best use…

Read article →
Software Testing

End to End Testing Best Practices: Boost Reliability in 2026

Flaky tests waste time and hide real bugs. Learn end to end testing best practices that make your tests stable,…

Read article →
Test Automation

Best Test Automation Framework 2026: Choose the Right One

Not sure which test automation framework to pick? Compare the main types, use a simple checklist, and see how Playwright,…

Read article →
Artificial Intelligence

AI Agents Best Practices: Deploy Reliable Intelligent Bots

AI agents can save hours of work, but only when they are built with care. Learn AI agents best practices…

Read article →
Test Automation

Test Automation Framework Example: Build a Scalable Suite

See a real test automation framework example with folder layout, page objects, test data and CI steps. Copy the structure…

Read article →
Software Testing

Best Test Automation Tools 2026: Top Picks for QA Teams

Compare the best test automation tools in 2026 for web, mobile and API testing. See what each tool does well,…

Read article →
Software Development

REST API Best Practices 2026: Build Scalable Services

Learn REST API best practices for 2026: clear URLs, correct status codes, versioning, pagination, security and error handling, with simple…

Read article →
Artificial Intelligence

MCP Stateless Architecture: What’s New in MCP 2026

The MCP 2026-07-28 spec removes sessions and the handshake. See how stateless MCP works, what breaks, what gets easier to…

Read article →
Artificial Intelligence

WebMCP Explained: How AI Agents Will Interact With Websites

WebMCP lets a website publish tools that AI agents can call directly. Learn the Declarative and Imperative APIs, code examples,…

Read article →
Databases & SQL

SQL Tutorial for Beginners: Complete Guide to SQL in 2026

Learn SQL from scratch. Create tables, insert and query data, filter, sort, group, join tables and use subqueries and indexes,…

Read article →
Software Development

Git Tutorial for Beginners: Complete Guide to Git and GitHub in 2026

Learn Git from zero. Create repositories, commit, branch, merge, fix mistakes and work with GitHub pull requests, using simple commands…

Read article →
DevOps

Docker Tutorial for Beginners: Complete Guide to Docker in 2026

New to Docker? Learn containers, images, Dockerfiles, volumes, networks and Docker Compose with simple commands and a small project you…

Read article →
Databases & SQL

Vector Databases Explained: How Vector Search and AI Databases Work in 2026

Vector databases search by meaning, not just keywords. Learn embeddings, similarity search, HNSW indexes, pgvector and how to choose the…

Read article →
Software Testing

API Testing with Postman: A Complete Guide for Beginners and QA Testers

Learn API testing with Postman from scratch. Send requests, read status codes, add auth, write test scripts, build collections and…

Read article →
DevOps

GitHub Actions CI/CD: A Complete Guide to Automating Software Builds, Tests and Deployments

Learn GitHub Actions from scratch. Build a CI/CD workflow that runs tests, builds your app and deploys it, with simple…

Read article →