Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 60 ยท Test Planning and Documentation

Writing Good Test Cases

Learn how to write clear, atomic, traceable manual test cases: ID, title, preconditions, steps, expected result and data, plus a validator you can run.

A test case is a written instruction that lets someone else (or you, six months from now) check one specific behavior and decide, without arguing, whether it works. The test idea lives in your head; the test case is what survives. A good one can be run by a new colleague on a Monday morning and give the same verdict you would have given.

Most weak test cases fail in the same ways. They say "check that login works" (which login? with what data? what counts as working?), they bundle five checks into one, or they list steps but never say what should happen. This lesson shows the anatomy of a solid test case, the habits that keep a suite readable, and a small validator that catches structural mistakes automatically. If you have not seen where test cases fit in the bigger picture, read Test Strategy and Test Plan first.

The validator below is a stand-in: it is a few lines of JavaScript that check the shape of a test case. Real test management tools (Jira add-ons, TestRail, spreadsheets) do the storing and reporting; the discipline of writing a good case is the same everywhere.

The anatomy of a test case

Whatever tool you use, a manual test case answers six questions.

What every test case needs

ID and title A unique tag and a one-line purpose.
Preconditions What must be true before step 1.
Steps Numbered actions, one action each.
Expected result What a correct system does.

If any of these is missing, two testers will disagree.

1 / 2

Here is a complete example, written the way you would paste it into a spreadsheet or a test tool.

TEXT
ID:            TC-LOGIN-004
Title:         Login is rejected for a correct user name with a wrong password
Requirement:   REQ-AUTH-02 (invalid credentials show an error, no session is created)
Priority:      High
Preconditions: User "[email protected]" exists and is active.
               The browser has no signed-in session.
Test data:     email = [email protected], password = WrongPass!1
Steps:         1. Open the login page.
               2. Enter the email from the test data.
               3. Enter the password from the test data.
               4. Click "Sign in".
Expected:      The page stays on the login form.
               The message "Email or password is incorrect" appears.
               The password field is cleared.
               No session cookie is set.
Cleanup:       None.

Notice what the example does not contain: no "verify it works", no "etc.", no assumptions about who is running it. Every value is concrete and every expected result can be observed.

Writing the title and preconditions

The title should state the behavior being checked and the condition that makes it interesting. Compare "Login test 4" with "Login is rejected for a correct user name with a wrong password". The second one tells a reader what failed from the test report alone, before opening the case. A useful pattern is action + condition + outcome.

Preconditions are the state that must exist before step 1: an account, a product in stock, a feature flag turned on, a particular role. Put them in the case instead of hiding them in the first step. If a precondition is expensive, that is a signal to share it across a group of cases (see Test Data and Test Environments), not to leave it implicit.

Steps and expected results

Write steps as short imperative sentences, one action per step, in the order a user would do them. "Enter the email and password and click Sign in" is three actions in one step; if the click fails, the report cannot say which action broke. Splitting also makes it easy to attach an expected result to a specific step when the case is long.

The expected result is the most important field and the one most often left vague. A good expected result is:

  • Observable: something you can see, read or measure (a message, a status, a database row, a response code).
  • Specific: exact text or exact values when they matter, and a clear statement of what must not happen.
  • Independent of the tester: two people reading it reach the same verdict.

"System handles the error gracefully" is not an expected result. "An inline error appears under the amount field and the Pay button stays disabled" is.

Atomic, independent, repeatable

Three habits keep a suite healthy as it grows.

One purpose per case (atomicity). A case that checks login, profile edit and logout in one run can only report one verdict. When it fails on step 9, you do not know whether steps 10 to 14 would have passed. Prefer several short cases. Long end-to-end scenarios have their place (see Use Case and Scenario Testing), but label them as scenarios.

Independence. A case should not rely on another case having run first. If TC-12 only works after TC-11 created a record, one failure cascades into many false failures. Put the setup into the preconditions of each case instead.

Repeatability. Running the case twice should give the same result. Avoid data that changes ("use today's top story"), and say how to restore the state if the test changes it. A case that can only be run once is a one-off check, not a test.

Write test cases for the reader, not for yourself. If a new team member could not run it without asking you a question, add the missing answer to the case.

Traceability and reuse

Every test case should point to the requirement, user story or risk it checks. That one field is what later lets you answer "which requirements have no tests?" and "which tests are affected if this requirement changes?" We build a full traceability matrix in Traceability and Test Estimation.

Where several cases share the same steps and only the data differs (valid email, empty email, email without @), write the steps once and list the data rows in a table. That is the manual equivalent of a data-driven test, and the rows usually come straight from Equivalence Partitioning and Boundary Value Analysis.

Try it: a test case validator

The first stand-in checks the structure of test cases the way a review checklist would: missing fields, vague wording, multiple actions in one step, and an expected result that cannot be observed. Press Run, then try removing the expected field from the second case.

JS Validate test-case structure

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The linter cannot judge whether a case is meaningful, only whether it is well formed. That is still valuable: it removes the boring review comments so humans can discuss the interesting ones.

Try it: turning a rule into data-driven cases

The second stand-in shows the "steps once, data in a table" idea. The rule under test is: a username must be 3 to 12 characters and use only letters and digits. The table lists the data and the expected result; the code plays the role of the tester and fills in the verdict.

JS One procedure, many data rows

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Each row has its own ID, so a failure is traceable to exactly one data value, and the why column documents the design reason (the same reason you would write in a review).

Common mistakes

  • Vague expected results such as "works" or "no errors". Always say what you will see.
  • Steps that describe the UI loosely ("go to settings"). Name the page, button or menu item exactly as it appears.
  • Copy-paste drift: ten cases that differ by one value are better as one case plus a data table.
  • Hidden dependencies on data or on earlier cases.
  • Over-documenting: a case that needs 40 steps is a scenario or a script in disguise. Split it, or turn it into an automated check.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which expected result is best?

    A good expected result is observable and specific, so any tester reaches the same verdict. The others use words that depend on opinion.
  2. 2. Why should a test case be atomic?

    When one case checks several behaviors, a failure at step 9 leaves the rest unknown. Short, single-purpose cases give clear verdicts.
  3. 3. TC-12 only works if TC-11 has already created a customer. What is wrong?

    Each case should state its own preconditions. Dependencies between cases make results unreliable and ordering fragile.
  4. 4. What is the main value of linking a test case to a requirement?

    That link is the raw material of a traceability matrix, which shows coverage gaps and the impact of changes.

Summary

  • A test case has an ID, a title, preconditions, steps, test data and an observable expected result, plus a link to a requirement.
  • Titles say what behavior under which condition; steps are numbered, one action each.
  • Expected results must be specific and observable, including what must not happen.
  • Keep cases atomic, independent and repeatable; put shared setup in preconditions.
  • Use data tables when only the values change, and a linter to catch structural mistakes.

Next: Test Data and Test Environments.