Process
Pairwise Testing
Last updated:
December 13, 2021
You should be familiar with the concept of [Classification Tree Partitioning](/codex/classification-tree-partitioning) before reading this article. The Classification Tree Partitioning technique allows us to obtain a set of equivalence classes even if the set of possible inputs is complex and involves multiple parameters. However, in case where each parameter can be split into multiple ways, the resulting classification tree may have too many leaves to be tested effectively. An optimization is generating a set of test cases where, for every pair of levels in the classification tree, we have one test case that covers all possible combinations of values at those levels. ### Worked example Consider the `claimComp` function in Compound Protocol. It has the following signature: ```solidity function claimComp(address[] memory holders, CToken[] memory cTokens, bool borrowers, bool suppliers) public; ``` Since the code is unlicensed, we won't share it here, but effectively the purpose of this function is to facilitate claiming of $COMP tokens on behalf of a certain set of holders: - `holders` are the addresses that $COMP will be claimed for - `cTokens` are the markets for which to claim $COMP in - `borrowers` is true if borrower $COMP should be claimed - `suppliers` is true if supplier $COMP should be claimed. We can create a classification tree for this function with the following layers: - A: Is there at least one holder specified in `holders`? - B: Is there at least one cToken specified in `cTokens`? - C: Is `borrowers` true? - D: Is `suppliers` true? As written, this classification tree would have 16 leaves and 16 test cases would have to be written. However, if we only care about each combination of values to be tested pairwise, we can get away with the following 6 test cases: - A & B & C & D - A & B & !C & D - A & !B & !C & !D. - !A & B & C & !D - !A & !B & C & D - !A & !B & !C & !D.
See Also: