Definition of a test case

Introduction

A test case describes the properties and behavior of a system.

Knowing what a test case is, will improve your documentation, specifications, and code by making them testable and easier to read and understand.

The concepts

A test case consists of:

  • Context – Can be written as a user story to give the right context
  • Preconditions – What needs to be ready before the test can start.
  • Actions – What steps need to be done to complete the test case.
  • Expected result – What needs to be expected, after the test case is complete.

It is mirrored in BDD (Behavior Driven Development) with Given, When, Then:

  • Feature / Scenario (Context)
  • Given (Preconditions)
  • When (Actions)
  • Then (Expected result)

And in TDD (Test Driven Development) with the triple A:

  • Title (Context)
  • Arrange (Preconditions)
  • Act (Actions)
  • Assert (Expected result)

The rules (behavior)

  1. A “given” is optional because sometimes no preconditions are needed, i.e. when only testing behavior. Example: When adding two and three, then the sum is five.
  2. A “when” is optional, because sometimes no actions are needed, i.e when testing properties. Example: Given a customer have a car from Henry Ford, then the color is black.
  3. A “then” is always present because a test case can’t exist without an assertion.
  4. Either a “given” or a “when” must be present – because a “then” requires something before it.

Multiple test cases in one

Lets look at the following test case:

  1. Given something
  2. When something
  3. Then something
  4. When something
  5. Then something

A test written as above should be avoided, because technically its two test cases and not one.

The first test case is

  • Precondition: step 1.
  • Action: step 2.
  • Expected result: step 3

The second test case is

  • Precondition: the first test case
  • Action: step 4.
  • Expected result: step 5.

Sometimes it is necessary. For example, GUI tests take minutes to execute, and it is inefficient to split the test case up and repeat “Test case 1” twice or more times.

Test case icon

Add a Comment

Your email address will not be published.