UML: Use Case Diagrams & Scenarios

From Use Cases to Test Cases

18 min Lesson 9 of 10

From Use Cases to Test Cases

A well-written use case scenario is not just a requirements artifact — it is the seed of an acceptance test. Every flow you documented in the previous lesson (main success flow, alternate flows, exception flows) maps directly to at least one test case. Analysts who understand this connection write sharper scenarios, and testers who understand it spend far less time inventing test inputs from scratch.

This lesson shows you the systematic technique for deriving a complete set of test cases from use case scenarios, using a clinic booking system as the running example.

Why Use Cases Make Great Test Seeds

Use case scenarios share three properties with test cases: they describe a precondition (the system and actor state before the interaction begins), a sequence of steps (actions and system responses), and a postcondition (what must be true when the scenario ends successfully or fails). Because that structure already exists in your scenario, you are not writing tests from scratch — you are translating existing analysis work into a test format.

The mapping rule is simple:

  • Each main success flow yields one happy-path test case.
  • Each alternate flow yields one or more variation test cases.
  • Each exception flow yields one or more negative test cases.
  • Each extension point (where an extend use case can trigger) yields tests for both the triggered and the non-triggered paths.
Acceptance tests vs unit tests: Test cases derived from use cases are system-level acceptance tests — they test an observable user goal end-to-end. They do not replace unit tests written by developers to cover internal logic. Analysts own the acceptance test specification; developers own the unit tests.

The Translation Technique — Step by Step

The following five steps convert a use case scenario into a formal test case specification. We will apply them to the Book Appointment use case from the clinic booking system.

Step 1 — Identify the scenario

List every scenario (main flow + all alternate and exception flows) in your use case. Give each one a short label. For Book Appointment:

  • BA-S1 — Patient books a valid appointment (main success flow)
  • BA-S2 — No available slots on selected date (alternate flow)
  • BA-S3 — Patient provides invalid ID format (exception flow)
  • BA-S4 — System timeout during slot confirmation (exception flow)

Step 2 — Assign preconditions and test data

Each scenario's precondition from the use case becomes the test's Given clause. Specify concrete test data: real doctor names, specific dates, exact ID strings. Concrete data makes tests repeatable and removes ambiguity about what "valid" means.

Step 3 — Derive the test steps

Each step in the scenario flow becomes a test action or system-check. Actions driven by the actor become When steps; expected system responses become Then assertions.

Step 4 — State the expected outcome

The postcondition of the scenario becomes the test's pass/fail criterion. For the main success flow, the expected outcome is a confirmation. For exception flows, the expected outcome is an appropriate error message and a stable system state.

Step 5 — Add boundary values and equivalence classes

Once you have the scenario-derived tests, augment each one with boundary values: the minimum and maximum allowed inputs, and values just outside those limits. This step is where use-case-derived tests and classic test design techniques (equivalence partitioning, boundary value analysis) intersect.

Diagram 1 — Mapping Flows to Test Cases

The diagram below illustrates how the three types of scenario flows in Book Appointment fan out into test cases, and how boundary-value augmentation adds additional coverage.

Use Case Flows to Test Cases Mapping Book Appointment (Use Case) Main Success Flow Alternate Flow (×1) Exception Flows (×2) TC-BA-01 Happy path: valid booking TC-BA-02 Alternate: no slots available TC-BA-03 Exception: invalid patient ID TC-BA-04 Exception: system timeout TC-BA-01a/01b Boundary: min/max lead time Scenario-derived test Negative test Boundary augmentation
Each scenario flow in a use case maps to one or more test cases; boundary analysis adds further coverage.

A Complete Test Case Derived from a Scenario

Below is the full specification for TC-BA-01, derived directly from the Book Appointment main success flow. Notice how the structure mirrors the use case scenario fields.

Test Case ID : TC-BA-01 Use Case : Book Appointment (main success flow) Title : Patient successfully books a future appointment Priority : High Preconditions: - Patient is logged in (session active) - At least one available slot exists for Dr. Nour on 2026-07-15 - Patient ID = P-10042 (valid format) Test Steps: 1. Navigate to Book Appointment screen 2. Enter Patient ID: P-10042 3. Select Doctor: Dr. Nour Al-Hassan 4. Select Date: 2026-07-15 5. Select Time Slot: 10:30 6. Click Confirm Expected Result: - Confirmation page shows: appointment reference #, doctor name, date, time - Appointment record saved in DB with status = PENDING - Confirmation email queued to patient@example.com - Slot 10:30 on 2026-07-15 marked unavailable Postcondition : System in stable state; patient can view booking in history Pass / Fail : [ ]

Contrast this with TC-BA-03, derived from the exception flow "Patient provides invalid ID format":

Test Case ID : TC-BA-03 Use Case : Book Appointment (exception flow EF-1) Title : System rejects booking when patient ID is malformed Priority : Medium Preconditions: - Patient is on the Book Appointment screen Test Steps: 1. Enter Patient ID: 10042 (missing P- prefix) 2. Fill in all other valid fields 3. Click Confirm Expected Result: - Form does NOT submit - Inline error shown: "Patient ID must be in format P-NNNNN" - No record written to DB - Slot availability unchanged Postcondition : User remains on form; can correct and resubmit Pass / Fail : [ ]

Diagram 2 — Coverage Matrix: Scenarios vs Test Cases

A test coverage matrix traces each test case back to the scenario that seeded it. It answers the question: "Have we covered every scenario?" and is a required deliverable in most formal QA processes.

Test Coverage Matrix: Book Appointment Use Case Scenario TC-BA-01 TC-BA-02 TC-BA-03 TC-BA-04 TC-BA-01a BA-S1: Main Success Flow (valid booking end-to-end) BA-S2: Alternate Flow (no slots available) BA-S3: Exception Flow 1 (invalid patient ID) BA-S4: Exception Flow 2 (system timeout) = Test covers this scenario = Boundary augmentation = Not applicable
A traceability matrix confirms that every scenario has at least one test case; gaps appear immediately as empty rows.

Applying the Technique Beyond Booking

The same technique scales to any domain. For an online store use case Place Order, the main success flow seeds a happy-path test; the alternate flow "item becomes out of stock during checkout" seeds a variation test; and exception flows "payment gateway refuses card" and "shipping address not serviceable" each seed a negative test. For a library system use case Renew Loan, the alternate flow "maximum renewals reached" and the exception flow "item reserved by another patron" both become distinct negative tests.

The pattern is universal. If your scenario documents are thorough — if they cover all the alternate and exception flows described in the previous lesson — your test suite will achieve broad acceptance coverage almost automatically.

Tip — traceable IDs from day one: Adopt a test case ID convention that embeds the use case name and flow type: TC-[UseCase]-[NN]. When a defect is found, the ID immediately tells reviewers which use case scenario it came from, which scenario was under-specified, and which analyst to involve in the fix.

When a Scenario Is Missing

Working backwards also works: if testers invent a test case that cannot be traced to any documented scenario, that is a sign your use case model is incomplete. The test case reveals a flow you forgot to document. Add the missing scenario to your use case write-up, update the traceability matrix, and investigate whether it also exposes a missing requirement in the system specification. This bidirectional traceability — from requirement to test and back — is one of the most powerful quality mechanisms in structured analysis.

Common pitfall — confusing test cases with test scripts: A test case specifies what to verify (steps, data, expected result). A test script specifies how to automate it (code, selectors, assertions). As an analyst your job is the test case specification; automation engineers translate those into scripts. Do not conflate the two or you will skip the specification step and produce untraceable automated tests.

Summary

Every scenario in a use case write-up — main success flow, alternate flows, exception flows — maps directly to one or more acceptance test cases. The translation follows a consistent five-step process: identify the scenario, assign preconditions and test data, derive test steps, state the expected outcome, and augment with boundary values. A traceability matrix links each test case back to its source scenario and reveals gaps in coverage. When every scenario has a test and every test has a scenario, you have achieved full acceptance coverage of your use case model.