IT lexicon › Programming › Property-based testing

Property-based testing

Programming På svenska → Updated: 2026-05-24

You write invariants (properties that should hold for every input) — the library generates hundreds of random inputs and tries to break them.

Invented in QuickCheck for Haskell (Claessen & Hughes, 1999). Classic examples: reverse(reverse(xs)) == xs, sort(xs).length == xs.length, encode(decode(x)) == x. On failure: shrinking reduces input to the smallest reproducer.

Popular libraries: Hypothesis (Python), fast-check (JS), proptest (Rust), ScalaCheck, jqwik. Finds bugs that handwritten unit tests miss, especially edge cases (empty list, negative numbers, unicode). Not a replacement for example-based tests — a complement.

← Back to the lexicon