TOPIC 10/5118 MINNOT STARTED

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.

  1. State the rule
  2. Generate inputs
  3. Shrink the failure
  4. Keep it as an example
State the domain and rule; keep a simpler failure

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
The rule: sorting twice equals sorting onceThe property
A thousand random listsThe generated inputs
Cutting the failing list downShrinking
Keeping the simplified failing list on a cardAn 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?

What each part of the trick stands for
In the trickWhat it stands for
what must holdState the rule that should always hold
which list breaks itLet a tool make lists and hunt for a case that breaks it
how smallShrink 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
  1. 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)

    States properties as functions and tests them on random inputs; users can write their own generators. · Checked 2026-10-18

    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.

  2. 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)

    Explains that Hypothesis generates inputs and shrinks a failing input to a simpler one. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-10-18

    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.

  3. 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)

    Shows the given decorator with strategies such as integers and lists, and that by default Hypothesis tries 100 inputs. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-10-18

    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.

  4. 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)

    Strategies define input domains and shrink behaviour; lists can specify an element strategy and size bounds, and integers can specify minimum and maximum values. · Checked 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.

  5. 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.

    Explains rejected generated inputs, discard limits and simpler failing examples. · Checked 2026-10-22

    The named primary sections were opened on the access date. The lesson does not generalise default counts or limits to other tools.

  6. 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.

    Shows how data type and the chosen comparison can change whether a property holds. · Checked 2026-10-22

    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.