Home / Market / property based testing

property based testing

Write property-based tests with Hypothesis, proptest, or fast-check. Design non-tautological invariants, avoid filtered generator starvation, shrink counterexamples, and pin CI seeds.

skill★ 507610 dlgithubCC-BY-4.0 content; MIT code; upstream exceptions applyInstall in CosmosUpstream Source

Documentation & Preview

--- name: property-based-testing description: "Write property-based tests with Hypothesis, proptest, or fast-check. Design non-tautological invariants, avoid filtered generator starvation, shrink counterexamples, and pin CI seeds." category: testing risk: safe source: self source_type: self date_added: "2026-11-30" author: ShianMike tags: [testing, property-based-testing, hypothesis, proptest, fast-check, invariants]

---

Property-Based Testing

When to Use

Prerequisites

Identify the language, test runner, and property-testing library (hypothesis in Python, proptest in Rust, or fast-check in TypeScript/JavaScript). Confirm the function's public contract, domain constraints (such as valid input ranges, NaN/infinity handling, or ordering guarantees), and runtime budget in CI.

Choose real invariants instead of tautologies

  1. Avoid re-implementing the production formula inside the test (which merely tests that two copies of the same bug agree). Pick independent mathematical or behavioral properties:

Construct healthy generators and shrink cleanly

Make CI deterministic and debuggable

Example

> An interval-merging utility passes simple overlapping unit tests but silently drops data on nested intervals such as [(0, 2), (1, 1)].

Run the worked Hypothesis invariants and shrinking test to verify that a coverage-oracle property catches the nested-interval bug and that the fixed implementation satisfies oracle, canonical-form, idempotence, and reversal invariants with a pinned @example.

Limitations

Safety and Side Effects

Run property suites against in-memory data or isolated disposable fixtures. Never point randomized generators at production databases, paid external APIs, or destructive filesystem paths. Keep generated example databases (.hypothesis/ or proptest-regressions/) aligned with repository ignore/commit conventions.

Related Skills and Documentation