# Property Based Testing

> Use when: test invariants over generated inputs instead of a few hand-picked examples.

- Skill: `kimtth/property-based-testing` (Agent Skill)
- Install (CLI): `npx skillmds@latest add kimtth/property-based-testing`
- Raw SKILL.md: https://api.skillmd.com/api/skills/kimtth/property-based-testing/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: kimtth (https://skillmd.com/u/kimtth)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/kimtth/property-based-testing

---


Goal: find edge cases by checking properties across many inputs.

Use for:
- logic with broad input ranges or many edge cases
- parsers, serializers, and data transformations
- complementing example-based tests

Workflow:
1. Identify an invariant that must always hold.
2. Define generators for the relevant input space.
3. Let the framework run many randomized cases.
4. Let it shrink failures to a minimal counterexample.
5. Add the counterexample as a regression test.
6. Refine generators to cover meaningful edges.

Useful properties:
- round-trip: decode(encode(x)) == x
- invariant: output always satisfies a rule
- equivalence: two implementations agree
- idempotence: f(f(x)) == f(x)

Rules:
- assert properties, not specific outputs
- constrain generators to valid, meaningful inputs
- pin discovered counterexamples as fixed tests
- use seeds so failures reproduce

