What is pairwise testing?
Pairwise testing requires every pair of values of any two parameters to appear in the set at least once, giving far fewer tests than full enumeration. It works because most defects come from one parameter or the interaction of two: three parameters with three values need nine tests instead of 27. The set is generated with constraints for impossible combinations, and risky triples are added by hand.
QA Fundamentals · Test design techniques
Three parameters with three values each give 27 combinations. Can you test fewer and lose nothing?
A settings form is opened in three browsers, under three account types and with three interface languages. Full enumeration is 27 runs, and with four parameters it is already 81. Add one more parameter, and the regression time no longer fits in a sprint. Pairwise testing shortens the set without losing the errors that occur most often.
How it works and why
An observation from practice: most defects are caused by a single parameter or the interaction of two. An error that shows up only when five values coincide is rare. Hence the idea: it is enough that every pair of values of any two parameters appears in the set at least once, and all full combinations are not needed.
Let us count on our example. There are three pairs of parameters (browser-account, browser-language, account-language), each with 3 × 3 = 9 value pairs, 27 pairs in total. One test with three values covers three pairs, so at least 27 / 3 = 9 tests are needed. That is three times fewer than full enumeration, and every pair such as "Chrome + Pro", "Safari + UK", "Free + EN" is guaranteed to appear.
Full enumeration and pairwise
All combinations: 27 tests
Checks everything, including what never breaks. For 4 parameters with 3 values it is already 81.
Pairwise: 9 tests
Every pair of values of two parameters appears at least once. For 4 parameters with 3 values only about 9-10 are needed.
Example: a set of nine tests
Here is a set in which every pair of values of two parameters appears at least once (for three parameters with three values this is an orthogonal array; a generator such as PICT builds a similar set heuristically, and it may be a few rows longer):
Nine tests cover all 27 pairs
| Test | Browser | Account | Language |
|---|---|---|---|
| 1 | Chrome | Free | UK |
| 2 | Chrome | Pro | EN |
| 3 | Chrome | Team | PL |
| 4 | Firefox | Free | EN |
| 5 | Firefox | Pro | PL |
| 6 | Firefox | Team | UK |
| 7 | Safari | Free | PL |
| 8 | Safari | Pro | UK |
| 9 | Safari | Team | EN |
In practice the set is generated, not composed by hand. One of the tools, Microsoft's PICT, takes a model of parameters and constraints:
Browser: Chrome, Firefox, Safari
OS: Windows, macOS, Linux
Account: Free, Pro, Team
IF [Browser] = "Safari" THEN [OS] <> "Linux";
The constraint removes impossible pairs: Safari does not run on Linux, so such combinations do not get into the set. Running pict model.txt prints a table of tests, which you then complete with the expected result.
Limits and alternatives
- Pairwise does not guarantee finding defects that need three or more values at once. For critical spots, add manual combinations or take stronger coverage (three-way sets).
- The values of the parameters are chosen first by other techniques: classes and boundaries give the representatives, pairwise only combines them.
- The set does not know the expected result. It is defined for each row separately, and it is often the same (the form works).
- Risky combinations (the most popular browser with a paid plan) are added on top of the set, even if the pairs are already covered.
- Pairwise is not one of the core CTFL v4.0 techniques, it is a common combinatorial testing practice.
Typical mistakes
- Not adding constraints. Impossible combinations get into the set, and tests fail for no reason.
- Feeding all values to the generator without selection. A parameter with 30 values inflates the set. Classes first.
- Treating the set as full protection. Pairwise lowers the risk but does not guarantee the absence of three-factor errors.
- Forgetting the expected result. Without it the set checks nothing.
Check yourself
Four parameters with three values each. How many combinations in full enumeration and what is the theoretical minimum of pairwise tests?
Answer
Full enumeration is 34 = 81. Pairwise needs at least 3 × 3 = 9 tests, because two parameters with three values need 9 different pairs, and each test holds exactly one pair of these two parameters. A generator usually gives 9-10.
A bug shows up only in Safari, on a Free account, in Ukrainian. Does a pairwise set guarantee it will be found?
Answer
No. Pairwise guarantees every pair, but not every triple. The triple "Safari + Free + UK" may not occur. If that combination is risky, it is added by hand.
Why constraints in the model?
Answer
They exclude impossible combinations (Safari on Linux). Without them the set contains tests that cannot be run, and the generator may cover the remaining pairs worse.