Property-based testing
State a rule that should always hold, let a tool try hundreds of inputs, and read the smallest failing one it finds.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: checking that a list sorted twice is the same as sorted once, with a thousand random lists instead of three chosen ones. If you pick three lists by hand, you pick the ones you thought of. A thousand random lists include ones you never would.
Daily List is a to-do list app. It sorts tasks by due day. Tom writes down a rule: after sorting, no task is lost. He does not write the answer for one list. He lets a tool make a hundred lists, with odd lengths and repeated days, and check the rule on each.
On the thirteenth try, the tool finds a list that breaks the rule. It is a list with the same day twice. Then it searches for a simpler failing list. In the reported teaching run it found two tasks on day 1.
This is property-based testing: stating a rule that should always hold and letting a tool hunt for a case that breaks it.
The picture has a limit. A thousand lists are still not every list. The tool can miss a rare case.
(SYNTHETIC / TRAINING ONLY: Daily List and every person named in this lesson are invented.)
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Stating a rule for every input, letting a tool hunt for a case that breaks it and reading a simpler failing case.
- State the rule
- Generate inputs
- Shrink the failure
- Keep it as an example
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The rule: sorting twice equals sorting once | The property |
| A thousand random lists | The generated inputs |
| Cutting the failing list down | Shrinking |
| Keeping the simplified failing list on a card | An example test for the bug |
WHERE THIS PICTURE STOPS
- A thousand lists are still not every list.
- Chosen lists are about what you know. Random lists reach what you do not.
- A card with one list records one case, not a rule.
HOOK
State the domain and rule, try inputs, keep the simpler failure.
REMEMBER IT THIS WAY
A sequence: the real steps, in order.
Ask in order: what must hold, which list breaks it, how small can that list get?
| In the trick | What it stands for |
|---|---|
| what must hold | State the rule that should always hold |
| which list breaks it | Let a tool make lists and hunt for a case that breaks it |
| how small | Shrink to a simpler failing list under the tool's search rules |
TELL A FRIEND
Checking that a list sorted twice is the same as sorted once, using many random lists instead of three chosen ones.
OFTEN MIXED UP WITH Unit tests for testers. The unit tests lesson writes tests with chosen inputs. This lesson states rules and lets a tool choose the inputs.
PRACTISE AND KEEP
Sources for this topic — 6 sources
- Market practice
QuickCheck: A lightweight tool for random testing of Haskell programs (Claessen and Hughes, 2000 conference paper) ↗ — ACM · Properties are written as functions and tested on random inputs; users can write their own generators (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: International Conference on Functional Programming 2000, pages 268 to 279. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
How Hypothesis Works (Hypothesis project) ↗ — Hypothesis project · The tool generates inputs and shrinks a failing input to a simpler one (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Quickstart (Hypothesis documentation) ↗ — Hypothesis project · The given decorator with strategies such as integers and lists; by default 100 inputs are tried (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Strategies Reference ↗ — Hypothesis project · Strategies define input domains and shrink behaviour; lists can specify an element strategy and size bounds, and integers can specify minimum and maximum values. (primary page opened and read, 2026-10-21)
Primary page opened and read on 2026-10-21. Scope is the claim described here; this does not upgrade earlier citations to other pages. Examples in Daily List are synthetic teaching examples.
- Implementation-specific
User Guide 1.10.2: assumptions and shrinking ↗ — Jqwik project · jqwik User Guide 1.10.2: Assumptions, Filtering and Result Shrinking. Primary sections opened 22 October 2026. The proposed-input counts below are invented, not a jqwik run.
The named primary sections were opened on the access date. The lesson does not generalise default counts or limits to other tools.
- Implementation-specific
FsCheck Quick Start: checking the property itself ↗ — FsCheck project · FsCheck Quick Start: FsCheck teaches us a lesson; F# float/NaN example and C# equality-comparer explanation. Primary body opened 22 October 2026.
Primary quick-start body opened and read on the access date. F# and C# examples differ in their handling of a special numeric value. Search behaviour in Daily List is an original teaching example.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.