How to Write Test Cases: A Step-by-Step Guide

Knowing how to write test cases well is one of the most practical skills in software testing. Clear, well-structured test cases make testing repeatable, give stakeholders evidence that requirements have been met, and make defects easier to trace back to their source. This guide explains how to write test cases step by step, from understanding the requirements through to traceability and maintenance, and includes a free downloadable test case template.

What is a test case?

A test case is a series of actions conducted to validate a particular feature or function during software testing. It provides a complete description of the steps, data, prerequisites and postconditions required to verify the feature. Test cases serve as a guide to determine whether the feature is working correctly.

How to write test cases: step by step

1. Identify the requirements

Understand the software’s functional and non-functional requirements. This will help you align your test cases with the desired functionality.

  • Review the project documentation: Start by thoroughly reviewing the project documentation, such as functional specifications, design documents, user stories and use cases. This will give you a clear understanding of the system and its expected behaviour.
  • Communicate with stakeholders: Engage in discussions with project stakeholders, including developers, product owners, business analysts and end users. This will help you gather additional information, clarify any ambiguities and understand their expectations.
  • Analyse user needs: Identify the needs and expectations of the end users. Understand their goals, objectives and the tasks they need to perform using the system. This will help you determine the critical functions that need to be tested.
  • Prioritise requirements: Prioritise the project requirements based on their importance and significance. This will help in setting test objectives that focus on the critical functions and features of the system.

2. Define test objectives

Test objectives are specific goals that define what needs to be achieved during the testing process. They provide direction and focus to the testing effort and help in evaluating the success of the testing activity.

  • Understand the project: Gain a clear understanding of the project requirements, scope and objectives. This will help in aligning the test objectives with the overall project goals.
  • Identify stakeholders: Identify the key stakeholders involved in the project, such as clients, end users, developers and project managers. Consider their perspectives and expectations while defining the test objectives.
  • Analyse risks: Identify the potential risks and uncertainties associated with the project. This will help in determining the critical areas that need to be tested and setting appropriate test objectives to mitigate those risks.
  • Define measurable goals: Ensure that the test objectives are specific, measurable, achievable, relevant and time-bound (SMART). This makes it easier to assess the progress and success of the testing activity.
  • Document the objectives: Document the test objectives clearly, along with the rationale behind each one. This serves as a reference for the testing team and provides clarity on the purpose and scope of the testing activity.

3. Define and prepare test data

Defining test inputs helps determine what data or values need to be provided to the system being tested. Preparing that test data properly is just as important: a well-written test case can still fail to run, or produce misleading results, if the data it depends on is missing, out of date or inconsistent. For a broader view of planning and governing test data across a programme, see Vansah’s test data management strategy guide.

To define test inputs:

  • Identify input sources: Determine where the inputs for the system come from. This could include user input, external data sources, databases, APIs or any other input mechanism.
  • Analyse input types: Identify the different types of inputs the system accepts, such as text, numbers, dates, files or other specific data types.
  • Consider boundary values: Determine the limits for each input type. Test inputs should include values at the minimum, at the maximum and beyond the expected range to confirm the system handles them correctly.
  • Consider different scenarios: Take into account conditions that might affect the inputs, such as different user roles, system configurations or environmental factors.

To prepare test data for your test cases:

  • Prepare data before execution: Create or load the required records in the test environment before testing starts, so testers are not building data in the middle of a test run.
  • Keep data independent: Where possible, give each test case its own data so that one test does not change the results of another.
  • Record the data in the test case: Note the specific values or records each test case uses so the test can be repeated and any defect can be reproduced.
  • Refresh and maintain: Review test data when requirements or environments change, and reset or refresh it between test cycles.

4. Create test cases

Creating test cases involves identifying the specific situations or conditions that need to be tested to confirm the software works correctly.

Each test case should have a unique test case ID and a headline. Make the headline as descriptive as possible; a concise phrase works best for readability, for example “Invalid Credential Login”.

A sample test case format should include the following. Download the template below:

Key points to follow:

  • Define positive and negative cases: Create test cases for both positive (valid inputs, expected outputs) and negative (invalid inputs, error handling) scenarios. Consider boundary conditions, edge cases and exceptional scenarios.
  • Prioritise: Prioritise test cases based on their importance, risk level and frequency of use.
  • Consider different user roles: If the software has multiple user roles, create test cases specific to each role to confirm the system behaves as expected for all user types.
  • Include integration and system-level scenarios: Create test cases that verify the interactions between components, modules or systems. Our integration testing playbook covers this in more depth.
  • Align test cases to stories: Each test case should align with a requirement or user story.

5. Include preconditions and prerequisites

Preconditions are the conditions that must be met before a test case can be executed. They put the system into the specific state or configuration the test needs, giving every run a consistent starting point and reliable, accurate results.

Examples of preconditions include:

  • System setup: The software is installed and configured correctly.
  • Data setup: The necessary test data is available in the system.
  • Environment setup: The test environment is properly set up, for example network connections and hardware devices.
  • User authentication: The user is logged in with the appropriate access rights.
  • Prerequisite tests: Any tests that must pass first have been executed successfully.
  • System state: The system is in the required state, such as a specific screen or module.
  • Dependencies: Any external dependencies required for the test are in place.

6. Write test steps and expected results

Outline the steps needed to execute each test case. Be thorough and include all necessary instructions. Steps should be easily repeatable and written from the end user’s perspective. They can be managed in a test management tool, a spreadsheet or a document.

  • Define test steps: Each step should have a clear objective and focus on a specific function or behaviour.
  • Describe the action: Write a clear, concise step that describes the action to perform. Use action verbs such as “click”, “enter”, “select” or “verify” to make it explicit.
  • Test data: Include the specific values or data used as input for the step.
  • Define expected results: State the expected result of each step; every step should have one. This is used to verify the actual result.

7. Maintain requirements traceability

Requirements traceability means establishing and maintaining a clear link between requirements (stories) and the tests that verify them. For a deeper look, see Complete Requirements Traceability, 360 degrees.

  1. Identify and document the requirements. Understand the project’s requirements and document them clearly and concisely, using a test management tool or a spreadsheet to record each one.
  2. Create a traceability matrix. The matrix shows the relationship between requirements and tests, making it easier to track progress and identify coverage gaps.
  3. Link requirements and test cases. Establish links between requirements and test cases in the matrix, either manually or with a test management tool that supports traceability, such as Vansah Test Management for Jira.
  4. Analyse coverage. Regularly review the matrix to confirm every requirement has associated test cases and that the tests cover all aspects of each requirement. Identify gaps and update the matrix.
  5. Maintain traceability. As the project progresses, update the matrix to reflect changes in requirements, test cases or test results so it stays current throughout testing.

8. Organise and maintain

Organise your test cases in a clear, structured way, and use a test case management tool to store them and track the execution status of each one.

  • Test case management tool: Use a tool that lets you create test cases, assign them to test cycles and track their execution status. Our overview of Jira test case management explains the options.
  • Categorise test cases: Group test cases by criteria such as functionality, component, module, priority or severity, so they are easier to locate and execute.
  • Use descriptive names: Give test cases meaningful names so testers and stakeholders understand their purpose and scope without reading the full description.
  • Review and update regularly: Keep test cases up to date with changes in the application under test, including checking that test steps and expected results are still valid.
  • Collaborate and communicate: Encourage feedback from the testing team and other stakeholders, and make sure everyone has access to the latest test case documentation.

Typical test case fields at a glance

FieldWhat to includeExample
Test case IDA unique identifierTC-LOGIN-002
HeadlineA short, descriptive nameInvalid Credential Login
Linked requirementThe story or requirement being verifiedUser login story
PreconditionsWhat must be true before the test runsRegistered account exists
Test dataSpecific input values or recordsValid username, incorrect password
Test stepsClear, repeatable actionsEnter credentials and click “Log in”
Expected resultThe outcome each step should produceError message shown, no session created
PriorityImportance based on risk and useHigh

By following these steps, you will know how to write test cases that are comprehensive and reliable, and that effectively validate the functionality of your software.

Need consistent, traceable test cases across your programme?

Tell us about the systems you are testing and how your test cases are managed today. We will help you design test cases and traceability that give your release decisions reliable evidence.

Book a consultation