A counterexample is an input that makes a tested property fail. In property-based testing, it demonstrates that the property does not hold universally and gives a concrete starting point for debugging. section 9.3.1
A useful counterexample workflow is:
- Generate inputs and evaluate the property. section 9.3.1
- Inspect the failing input to identify the behavior that violates the property. section 9.3.1
- Shrink the input and recheck it repeatedly until no smaller failing value remains. section 9.4.3
- Use the smaller, repeatable case to classify and fix the underlying bug or incorrect property. section 9.3.1
A failing rotation property
Testing the symmetry property s == rot13 (rot13 s) finds the counterexample "a" after two tests and one shrink. The reduced input exposes a single-character rotation problem more clearly than a long random string. section 9.3.1
ghci> symbols = upperAlphabet ++ lowerAlphabet ++ digits ghci> rot13' = map $ (\ch -> if ch `elem` symbols then alphabetRot symbols 13 ch else ch) ghci> prop_rot13Symm s = s == rot13' (rot13' s) ghci> quickCheck prop_rot13Symm *** Failed! Falsified (after 2 tests and 1 shrink): "a"
This QuickCheck session shows a property failing with the compact counterexample "a". section 9.3.1

