How to write Test Cases in Software Testing?

A TEST CASE is a documented set of preconditions (prerequisites), procedures (inputs / actions) and postconditions (expected results) which a tester uses to determine whether a system under test satisfies requirements or works correctly. A test case can have one or multiple test scripts and a collection of test cases is called a test suite.

ISTQB Definition

  • test case: A set of preconditions, inputs, actions (where applicable), expected results and postconditions, developed based on test conditions.
  • high-level test case: A test case with abstract preconditions, input data, expected results, postconditions, and actions (where applicable).
  • low-level test case: A test case with concrete values for preconditions, input data, expected results and postconditions and detailed description of actions (where applicable).

Typical Test Case Parameters

  • Test Case ID
  • Test Scenario
  • Test Case Description
  • Test Steps
  • Prerequisite
  • Test Data
  • Expected Result
  • Test Parameters
  • Actual Result
  • Environment Information
  • Comments

Test Case Template

A test case can have the following elements. Note, however, that a test management tool is normally used by companies and the format is determined by the tool used.

Test Suite ID The ID of the test suite to which this test case belongs.
Test Case ID The ID of the test case.
Test Case Summary The summary / objective of the test case.
Related Requirement The ID of the requirement this test case relates/traces to.
Prerequisites Any prerequisites or preconditions that must be fulfilled prior to executing the test.
Test Script  / Procedure Step-by-step procedure to execute the test.
Test Data The test data, or links to the test data, that are to be used while conducting the test.
Expected Result The expected result of the test.
Actual Result The actual result of the test; to be filled after executing the test.
Status Pass or Fail. Other statuses can be ‘Not Executed’ if testing is not performed and ‘Blocked’ if testing is blocked.
Remarks Any comments on the test case or test execution.
Created By The name of the author of the test case.
Date of Creation The date of creation of the test case.
Executed By The name of the person who executed the test.
Date of Execution The date of execution of the test.
Test Environment The environment (Hardware/Software/Network) in which the test was executed.

 

Writing Good Test Cases

  • As far as possible, write test cases in such a way that you test only one thing at a time. Do not overlap or complicate test cases. Attempt to make your test cases ‘atomic’.
  • Ensure that all positive scenarios AND negative scenarios are covered.
  • Language:
    • Write in simple and easy-to-understand language.
    • Use active voice instead of passive voice: Do this, do that.
    • Use exact and consistent names (of forms, fields, etc).
  • Characteristics of a good test case:
    • Accurate: Exacts the purpose.
    • Economical: No unnecessary steps or words.
    • Traceable: Capable of being traced to requirements.
    • Repeatable: Can be used to perform the test over and over.
    • Reusable: Can be reused if necessary.