---
title: "Property-Based Testing"
description: "Instead of listing examples, state a property that should hold for every input and let the machine generate inputs trying to break it. Good properties are relations that must survive, such as encoding"
canonical: https://lightmysky.com/learn/computing/property-based-testing-mt_QqCNKT06IY
source: https://lightmysky.com/learn/computing/property-based-testing-mt_QqCNKT06IY.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Property-Based Testing

Instead of listing examples, state a property that should hold for every input and let the machine generate inputs trying to break it. Good properties are relations that must survive, such as encoding then decoding returning the original.

Subject: Computing · Area: Software Engineering · Ages 20 to 22
Page: https://lightmysky.com/learn/computing/property-based-testing-mt_QqCNKT06IY

## Ready when they can

- Write a property that a sorting function must satisfy for any input list
- Explain what shrinking does to a failing case and why it helps
- Say which faults example tests catch that property tests usually miss

## Lesson: State the rule, let the machine attack it

You already know the test levels and where each belongs. Property tests add a new style. Instead of listing examples, you state one rule that must hold for every input, and the machine generates hundreds of inputs trying to break it.

**Example.** Take sorting. A good property says the output is ordered and holds the same elements as the input. Another classic says decoding an encoded value returns the original. A parser and its printer must satisfy the same kind of round-trip rule.

When an input breaks the rule, shrinking kicks in. It trims the failing input down to the smallest one that still fails. A tiny failing case points straight at the cause, while the original thousand-element monster hides it.

**Tip.** Example tests still matter. They pin down exact outputs and concrete business rules that a general property cannot see. Use properties to hunt surprises and examples to lock behaviour in.

**Recap.** State a rule for every input, let generated inputs attack it, and shrink failures to their smallest form.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Test Strategy: Unit, Integration and End to End](https://lightmysky.com/learn/computing/test-strategy-unit-integration-and-end-to-end-mt_fdAvx1MMFE)
- [Loop Invariants and Proving an Algorithm Correct](https://lightmysky.com/learn/computing/loop-invariants-and-proving-an-algorithm-correct-mt_fWnstju2ns)
- [Statements, Quantifiers and Negation](https://lightmysky.com/learn/mathematics/statements-quantifiers-and-negation-mt_S5NvyPxEZ_)

## Opens up

- [Specifying Correctness: Safety, Liveness and Invariants](https://lightmysky.com/learn/computing/specifying-correctness-safety-liveness-and-invariants-mt_4_KaoDSHZF)
- [Reproducibility: Seeds, Environments and the Ablation](https://lightmysky.com/learn/computing/reproducibility-seeds-environments-and-the-ablation-mt_Rp__eJ-vjn)
- [Continuous Integration and the Build Pipeline](https://lightmysky.com/learn/computing/continuous-integration-and-the-build-pipeline-mt_z__G4nfjwh)
