# Test Case Design — Equivalence Classes, Boundary Value Analysis, Decision Tables and State Transitions

Source: https://skills101.in/learn/software-engineering/software-engineering-test-case-design — Skills101 free tutorial (Software Engineering). Updated 2026-11-21.

An exam-registration form accepts **age 18 to 25** and **marks 40 to 100**. Testing every possible pair is impossible in practice, and most pairs would test the same thing anyway. **Test case design techniques** pick a small set of inputs that is still likely to find the bugs. The testing lesson introduced them in two lines; here you will apply each one fully, the way semester exams and QA interviews ask.

All four techniques here are **black-box**: they use only the specification (what the program should do), not the code.

## 1. Equivalence partitioning (EP)

Split each input into **classes** (partitions) whose values the program should treat the same way. If one value from a class works, the others very likely work too, so you test **one value per class**.

For age (valid range 18–25):

| Class | Values | Valid? | Pick |
|---|---|---|---|
| E1 | age < 18 | invalid | 15 |
| E2 | 18 ≤ age ≤ 25 | valid | 21 |
| E3 | age > 25 | invalid | 30 |
| E4 | not a number ("abc", blank) | invalid | "abc" |

Rules that examiners look for:

- Each class gets **one** test case. A range normally gives **one valid and two invalid** classes.
- Also think of invalid **types**: blank, letters, negative numbers, decimals where only whole numbers are allowed.
- **Combine valid classes** of different inputs in one test, but test **each invalid class on its own**. If one test has two invalid inputs and the form rejects it, you cannot tell which check worked.

## 2. Boundary value analysis (BVA)

Programmers often write `<` where they meant `<=`, so bugs gather at the **edges** of ranges. BVA tests values at and next to each boundary:

![Number line for age 18 to 25: boundary value analysis tests 18, 19, 24 and 25 plus a nominal value 21; robust testing also tests 17 and 26 just outside the range](https://skills101.in/learn-img/software-engineering/bva-number-line.svg)

| Variant | Values tested for one variable | Test cases for n variables |
|---|---|---|
| **Normal BVA** | min, min+1, nominal, max−1, max | **4n + 1** |
| **Robust** | the above + min−1, max+1 | **6n + 1** |
| **Worst-case** | all 5 values of every variable combined | **5ⁿ** |
| **Robust worst-case** | all 7 values combined | **7ⁿ** |

Where does 4n + 1 come from? BVA uses the **single fault assumption**: failures are usually caused by one variable at an extreme. So keep every variable at its nominal (middle) value, and move **one** variable at a time through its four boundary values. That gives 4 cases per variable, plus 1 case with everything nominal.

The program below generates the normal BVA cases for our form:

```python
def bva(ranges):
    nominal = {k: (lo + hi) // 2 for k, (lo, hi) in ranges.items()}
    cases = [dict(nominal)]
    for k, (lo, hi) in ranges.items():
        for v in (lo, lo + 1, hi - 1, hi):
            c = dict(nominal)
            c[k] = v
            cases.append(c)
    return cases

cases = bva({'age': (18, 25), 'marks': (40, 100)})
print(len(cases), 'test cases')
for c in cases:
    print(c['age'], c['marks'])

n = 2
print('robust:', 6 * n + 1, ' worst-case:', 5 ** n, ' robust worst-case:', 7 ** n)
```

```text
9 test cases
21 70
18 70
19 70
24 70
25 70
21 40
21 41
21 99
21 100
robust: 13  worst-case: 25  robust worst-case: 49
```

With n = 2: 9 normal cases, 13 robust, 25 worst-case and 49 robust worst-case. Worst-case testing grows fast — with 5 inputs it is 5⁵ = 3,125 cases — so it is kept for critical code.

**BVA vs EP:** EP picks any value from a class; BVA picks values at the class edges. In practice they are used together: EP finds the classes, BVA chooses the values.

## 3. Decision table testing

When the output depends on a **combination of conditions**, list every combination in a table. Example rule: *a student gets a fee waiver if marks are 85 or more, OR if family income is below ₹3 lakh AND attendance is at least 75%.*

- Conditions: C1 marks ≥ 85, C2 income < ₹3 lakh, C3 attendance ≥ 75%.
- With 3 yes/no conditions there are 2³ = **8 rules** (columns).

```python
from itertools import product

for rule, (c1, c2, c3) in enumerate(product('YN', repeat=3), start=1):
    waiver = c1 == 'Y' or (c2 == 'Y' and c3 == 'Y')
    print(f'R{rule}: marks>=85={c1} income<3L={c2} attend>=75={c3} -> {"waiver" if waiver else "no waiver"}')
```

```text
R1: marks>=85=Y income<3L=Y attend>=75=Y -> waiver
R2: marks>=85=Y income<3L=Y attend>=75=N -> waiver
R3: marks>=85=Y income<3L=N attend>=75=Y -> waiver
R4: marks>=85=Y income<3L=N attend>=75=N -> waiver
R5: marks>=85=N income<3L=Y attend>=75=Y -> waiver
R6: marks>=85=N income<3L=Y attend>=75=N -> no waiver
R7: marks>=85=N income<3L=N attend>=75=Y -> no waiver
R8: marks>=85=N income<3L=N attend>=75=N -> no waiver
```

Each rule becomes one test case. Rules R1–R4 all give "waiver" whatever C2 and C3 are, so they can be **collapsed** into one rule written as `Y – –` (the dash means "does not matter"). The table then has 5 rules instead of 8. The real value of a decision table is that it exposes combinations the specification forgot: what happens when marks are exactly 85, or attendance is not yet recorded?

**Cause–effect graphing** is a related technique: causes (input conditions) and effects (outputs) are joined with AND, OR and NOT in a graph, and the graph is then converted into a decision table.

## 4. State transition testing

Some systems react differently to the **same input** depending on what happened before. An ATM card PIN: three wrong attempts block the card. Draw the **states** and the **events** that move between them:

![ATM PIN state transition diagram: from Waiting for PIN a correct PIN leads to Access granted; a wrong PIN leads to Second try, then Third try, and a wrong PIN on the third try leads to Card blocked](https://skills101.in/learn-img/software-engineering/pin-states.svg)

Test cases come from the diagram:

- **Every state** visited at least once.
- **Every transition** taken at least once (stronger), e.g. wrong → correct, wrong → wrong → wrong.
- **Invalid transitions**: a PIN entered after the card is blocked must be refused.

```python
def atm(attempts, correct='4321'):
    state = 'try 1'
    for pin in attempts:
        if state in ('granted', 'blocked'):
            break
        if pin == correct:
            state = 'granted'
        else:
            n = int(state[-1])
            state = 'blocked' if n == 3 else f'try {n + 1}'
    return state

tests = [['4321'], ['1111', '4321'], ['1111', '2222', '4321'],
         ['1111', '2222', '3333'], ['1111', '2222', '3333', '4321']]
for t in tests:
    print(len(t), 'attempt(s) ->', atm(t))
```

```text
1 attempt(s) -> granted
2 attempt(s) -> granted
3 attempt(s) -> granted
3 attempt(s) -> blocked
4 attempt(s) -> blocked
```

The last test is the important invalid transition: a correct PIN after blocking must **not** give access.

## 5. Choosing a technique

| Situation | Best technique |
|---|---|
| Input with ranges (age, amount, marks) | Equivalence partitioning + BVA |
| Business rules with many conditions | Decision table |
| Behaviour depends on history (login, order status, traffic light) | State transition |
| Many independent options (browser × OS × language) | Pairwise (all-pairs) testing: cover every pair of values, not every combination |
| Testers' experience of typical bugs | Error guessing (empty file, zero, very long text) |

## Common mistakes

- Writing two invalid inputs in one EP test case. Test each invalid class alone.
- Using 4n + 1 for robust testing. Robust adds min−1 and max+1, giving **6n + 1**.
- Mixing up **worst-case 5ⁿ** (all combinations) with **normal BVA 4n + 1** (one variable at a time).
- Forgetting the nominal case in the count (the "+1").
- In state testing, testing only valid paths. The blocked card accepting a PIN is the dangerous bug.

## Quick recap

- EP: one test per class; a range gives one valid and two invalid classes.
- BVA: min, min+1, nominal, max−1, max. Counts: 4n+1 normal, 6n+1 robust, 5ⁿ worst-case, 7ⁿ robust worst-case.
- Decision table: 2ⁿ rules for n yes/no conditions; collapse rules with "don't care" dashes.
- State transition: cover every state, every transition and the invalid transitions.


Practice quiz and free certificate: https://skills101.in/learn/software-engineering/software-engineering-test-case-design