property-based-testing
Installation
SKILL.md
Property-Based Testing (PBT)
Instead of asserting f(3) == 9, assert a property that must hold for all inputs; the framework generates hundreds of cases, then shrinks any failure to a minimal counter-example.
Find properties (the hard part) — 7 patterns
- Round-trip:
decode(encode(x)) == x(serializers, parsers, compress, crypto). - Invariant:
len(sort(xs)) == len(xs), output is ordered, total money conserved. - Idempotence:
f(f(x)) == f(x)(normalize, dedupe, PUT). - Oracle: compare with a slow/simple reference implementation.
- Metamorphic:
search(q + filter) ⊆ search(q);price(2×qty) == 2×price(qty). - Commutativity/associativity where the domain promises it.
- No-crash / postcondition: for any valid input, no exception and result satisfies the contract.