The idea: test every pair, not every combination

A checkout page must work on many setups. The page uses four parameters: Browser (Chrome, Firefox, Safari), OS (Win, Mac, Linux), Lang (EN, FR, VI) and Pay (Card, PayPal, Bank). Testing every combination takes 3 × 3 × 3 × 3 = 81 tests. Add one more parameter and it is 243. The count grows exponentially.

A 9 by 9 grid of all 81 combinations, rows are Browser and OS, columns are Lang and Pay. Nine cells are marked, one in each row and each column: the 9 tests of a pairwise suite
81 combinations, but 9 well-chosen tests already contain every pair of values.

Studies of real failures found that most bugs are triggered by one value or by two values together, for example "PayPal fails in Firefox". So pairwise testing (also called all-pairs testing) asks for less: every pair of values of every two parameters must appear in at least one test. Which values the parameters get is decided first, for example with Equivalence Partitioning and Boundary Value Analysis.

Counting pairs

Four parameters make 6 parameter pairs: Browser × OS, Browser × Lang, Browser × Pay, OS × Lang, OS × Pay and Lang × Pay. Each has 3 × 3 = 9 value pairs, so there are 54 pairs. The right side of the canvas draws them as six 3 × 3 blocks.

One test, for example (Chrome, Win, EN, Card), touches one cell in each block: it covers 6 pairs. So at least 54 / 6 = 9 tests are needed. The Browser × OS block alone also needs 9 tests, one per cell. In general the two largest parameters set the lower bound: v1 × v2 tests.

Orthogonal array L9

For 4 parameters with 3 values each there is a perfect answer: the orthogonal array L9(34). Number the values 0, 1, 2. For i and j from 0 to 2, the test is (i, j, i + j mod 3, i + 2j mod 3). That gives 9 rows, and every pair appears in exactly one of them. Demo 1: orthogonal array L9.

The 9 rows of L9: test, i, j, and the four values from the formulas. Next to it the Browser by Pay block, where each of the 9 cells holds a different test, T1 to T9
L9 builds 9 rows from two formulas; in every block each cell is hit by exactly one test.

Orthogonal arrays come from statistics (design of experiments). They exist only for some sizes, and they need every parameter to have the same number of values.

Greedy generation, one test at a time

Tools such as AETG and PICT build a suite with a greedy loop. Each round looks at the candidate tests and adds the one that covers the most pairs not covered yet. The loop stops when every pair is covered. The page tries every allowed combination as a candidate and breaks a tie by taking the first one in order (Chrome before Firefox, Win before Mac, and so on), so the result is always the same. Demo 4: greedy, one test at a time. On 4 × 3 values it finds 9 tests too, each adding 6 new pairs.

Greedy works for uneven parameters. With Lang ∈ {EN, VI} and Pay ∈ {Card, PayPal} there are 3 × 3 × 2 × 2 = 36 combinations and 9 + 6 + 6 + 6 + 6 + 4 = 37 pairs. The rounds add 6, 6, 6, 6, 4, 4, 3, 1, 1 new pairs: 9 tests, the lower bound of the 3 × 3 Browser × OS block. Demo 5: uneven 3 × 3 × 2 × 2. The last rounds add only a pair or two; that tail is typical of greedy suites.

Constraints

Some combinations cannot exist. Say Safari runs only on Mac: Safari + Win and Safari + Linux are forbidden. That removes 2 pairs (52 left) and 18 combinations (63 left).

A fixed array breaks. Two rows of L9 put Safari on Win or Linux; dropping them loses their other pairs, and only 7 tests covering 42 of 52 pairs remain. Demo 6: a constraint breaks the L9 array. The greedy loop simply never picks a forbidden candidate. It needs 11 tests for all 52 pairs, two more than without the constraint. Demo 7: constraint, greedy covers every allowed pair.

ConfigAll combinationsPairsL9Greedy
4 × 3 values81549 tests, 54 / 549 tests, 54 / 54
3 × 3 × 2 × 23637does not fit9 tests, 37 / 37
Safari only on Mac63527 tests, 42 / 5211 tests, 52 / 52

What pairwise finds and what it misses

A bug that needs two values is always found, because its pair is in some test. Firefox + PayPal sits in T4 of L9: 1 of 9 tests fails. Running all 81 combinations shows 9 failures of the same bug, which tells nothing new. Demo 2: a pair bug.

A bug that needs three values can slip through. Say the checkout fails only with Firefox + Linux + VI. L9 has each of the three pairs, but in three different tests, so all 9 pass. All 81 combinations would find it in 3 tests. Demo 3: a 3-way bug.

Three passing tests of L9: T3 covers Linux and VI, T5 covers Firefox and VI, T6 covers Firefox and Linux. No test has Firefox, Linux and VI together, so the 3-way bug is missed
Every pair of the bug is covered, but never all three values in one test.

The number of values that must meet is the interaction strength t. Pairwise is t = 2. A t-way suite (a covering array of strength t) covers every combination of t values. For a fixed t its size grows only with the logarithm of the number of parameters, so 3-way and 4-way suites are still practical when pairwise is not enough.

Bug needsL9 (9 tests)All combinations (81)
Firefox + PayPal (2 values)✓ 1 of 9 fails✓ 9 of 81 fail
Firefox + Linux + VI (3 values)✗ missed, 0 fail✓ 3 of 81 fail

Pairwise testing is a black-box technique: it chooses inputs from the parameters, not from the code. To check how much of the code the tests reach, see Control-Flow Coverage, Condition Coverage and MC/DC and Data-Flow Testing. To check whether the tests would notice a bug at all, see Mutation Testing.

What the page leaves out

The page does not cover how real generators choose candidates: AETG draws about 50 random candidates per round, and IPOG grows the suite one parameter at a time instead of one test at a time. It also leaves out mixed-strength suites (3-way for some parameters only), seeding a suite with tests that must be in it, negative values (one invalid value per test), the expected-result problem for many tests, and the exact known sizes of covering arrays. The tests never run real code: the bug is a fixed rule on the four values.

On the mind map

Open the Software Design mind mapSoftware DesignPrinciples: keep each change localPrinciplesDesign patterns: named fixes for common designsDesign patternsArchitecture: the shape of a whole appArchitectureEnterprise app patterns: logic, SQL, locks, money (PoEAA)Enterprise app patternsGit storage: content named by its hashGit storageGit branches & merging: pointers to commits, then mergeGit branches & mergingTesting: check code in isolationTestingSOLIDSOLIDfive rules so one change hits one classInheritance vs compositionInheritance vs compositionis-a locks the tree; has-a mixes partsVirtual calls, vtableVirtual calls, vtableobject → vptr → vtable slot → functionC++ object layoutC++ object layoutB* to a C adds 16; virtual base is sharedOverloading vs overridingOverloading vs overridingjavac: static types; JVM: receiver's classCoupling and cohesionCoupling and cohesionOne change should touch one moduleControl-flow coverageControl-flow coverage100% statements can still miss a bugDef-use pairs (data flow)Def-use pairs (data flow)A wrong def shows only if it reaches a usePairwise testing9 tests cover all 54 pairs, not 81Boundary Value TestingBoundary Value TestingBugs sit at class edges: test min−1 … max+1Condition Coverage and MC/DCCondition Coverage and MC/DCEach condition flips D alone: N+1 testsMutation testingMutation testingCoverage runs code; mutants test the assertsOpen the Software Design mind mapSoftware Designkeep each change localPrinciplesSOLIDSOLIDfive rules so one change hits one classInheritance vs compositionInheritance vs compositionis-a locks the tree; has-a mixes partsVirtual calls, vtableVirtual calls, vtableobject → vptr → vtable slot → functionC++ object layoutC++ object layoutB* to a C adds 16; virtual base is sharedOverloading vs overridingOverloading vs overridingjavac: static types; JVM: receiver's classCoupling and cohesionCoupling and cohesionOne change should touch one moduleControl-flow coverageControl-flow coverage100% statements can still miss a bugDef-use pairs (data flow)Def-use pairs (data flow)A wrong def shows only if it reaches a usePairwise testing9 tests cover all 54 pairs, not 81Boundary Value TestingBoundary Value TestingBugs sit at class edges: test min−1 … max+1Condition Coverage and MC/DCCondition Coverage and MC/DCEach condition flips D alone: N+1 testsMutation testingMutation testingCoverage runs code; mutants test the asserts
This page on the Software Design mind map · 43 pages in 7 branches · open it to see the whole map and test yourself in recall mode.