Avoiding Test-Case Permutation Blowout - Steven Hicks

Posted . Visible to the public.

Sometimes you want to write a test for a business rule that's based on multiple variables. In your goal to cover the rule thoroughly, you start writing tests for each permutation of all variables. Quickly it blows up into something unsustainable. With n variables for the business rule, you get 2n permutations/test cases. This is manageable with 2 variables (4 test cases), but at 3 variables (8 test cases) it becomes ridiculous, and anything beyond that feels immediately uncomfortable.

I've noticed myself using an alternate pattern for this, which results in n+1 test cases instead of 2n. It gives good coverage despite not testing all permutations, and I actually think the test cases themselves become easier to follow.

Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2024-09-09 08:31)