QA Interview Hub · Knowledge base · Quizzes · Українська

QA Fundamentals › Test design techniques

Use case testing

Use case testing derives tests from a description of how an actor reaches a goal: the main scenario, alternative branches and exceptions. It is black-box, and minimal coverage means the main scenario plus every branch at least once. Each case also checks the postcondition, for example that exactly one order was created. The technique covers data variation poorly, so equivalence classes and boundaries are added.

QA Fundamentals · Test design

The main scenario works, but the payment is declined. What should happen then, and who checked it?

A tester walked through checkout from the cart to confirmation: all fine. In production a user enters a card with a zero balance, the system "hangs", the cart empties and there is no order. The main path was checked, but the branches where something goes wrong were not. Use case testing is exactly about this: a scenario has not only a happy path but also alternatives and exceptions, and each of them needs a test.

How it works and why. A use case describes how an actor (a user or another system) reaches a goal through interaction with the system. It consists of a name and goal, an actor, a precondition (the state before it starts), a main scenario in steps (the actor acts, the system responds), alternative flows (another but valid path, often returning to the main one), exceptions (an error, a refusal) and a postcondition (the state after). The technique is black-box: tests are derived from behaviour, not from code. It is convenient because a use case is written the way a person goes through a flow, so it finds defects at the joints of steps that equivalence classes do not see: the state after a refusal, going back a step, lost data.

A use case example

UC-7 Place an order
Actor: customer (signed in)
Precondition: the cart has an item
Main scenario:
 1. The customer presses "Checkout".
 2. The system shows addresses and delivery.
 3. The customer picks an address and delivery.
 4. The system shows the summary.
 5. The customer pays by card.
 6. The system confirms the order.
Alternatives:
 3a. No address: the customer adds one,
     then step 3.
 5a. Payment declined: the system offers
     another card, then step 5.
Exception:
 5b. Item is gone: the system reports it,
     no order is created.
Postcondition (success): the order exists,
                         the item is reserved

Where the scenario branches

Steps 1-3: address and deliverybranch 3a: no address, add a new oneStep 5: pay by card5a: declined, 5b: out of stockStep 6: order confirmedpostcondition: the order exists
Figure 1. The main path goes through all the steps, while alternatives 3a, 5a and 5b branch off specific steps and need tests of their own.

Example: from a use case to test cases. The minimum coverage of a use case is the main scenario and each alternative or exception flow at least once. Here are four tests:

TestPathExpected
TC-1steps 1-6the order exists
TC-23a, then 3-6address saved, order exists
TC-35a, then 5-6another card passes, one order
TC-45ba message, no order

In each case you check not only the screen but also the postcondition: whether exactly one order was created (TC-3 proves it, because the declined attempt must not create one), whether the item is reserved, whether money was not charged twice. The defect "the cart empties after a refusal" is caught by TC-3 exactly when the final state is stated explicitly.

Limits and alternatives. A use case describes data variations poorly: what happens if the card is expired and the promo code is also invalid, the scenario will not show. For that, equivalence classes and boundary values are added to a step, and a decision table for complex combinations of conditions. If states and transitions matter in the system (an order "new, paid, shipped"), state transition testing works better. In Agile a user story with acceptance criteria often replaces a use case, and each criterion yields a test. The quality of the tests depends on the quality of the use case: with a vague description you first need to clarify the expectations. Coverage is counted by scenario branches, not by code, so 100% coverage of use case branches does not mean every data combination was checked.

Typical mistakes.

  • Checking only the main scenario: most real defects are in refusals and returns.
  • Not checking the postcondition: the screen showed "error" but a half-created record stayed in the database.
  • Mixing everything into one case ("go through the main path and all the branches"): when it fails you cannot see which branch broke.
  • Trying only valid data at each step: a use case does not replace test design for data.
  • Taking a use case as the truth without questions: it has gaps too, worth asking an analyst about.

Check yourself

A use case has two steps with branches: one branch at step 3 and two at step 5. How many tests does the minimum coverage need and why not more?

Answer

Four: the main scenario and one test for each of the three branches. Every path is passed at least once, and trying all combinations of branches is not required, because that is a different (combinatorial) coverage with a different cost.

Test TC-3 (payment declined, a second card passes) passed on the screen, but the database holds two orders. What is the defect and what was missed?

Answer

The declined attempt created an order. The postcondition check was missed: after branch 5a exactly one order must remain. In a use case the final state of each branch is checked explicitly.

In an interview. Junior: A use case describes in steps how a user reaches a goal, with a main path and branches for errors. I derive tests from it: the main scenario and one test for each alternative or exception. Middle/Senior: It is a black-box technique that catches defects at the joints of steps and in the state after a refusal, so I check the postcondition of every branch explicitly. The weakness of the technique is data: I add variations with equivalence classes, boundaries and a decision table, and when states matter, with state transitions. In Agile it flows into tests from the acceptance criteria of a user story.

More articles in this chapter