Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Agent Skill

Property-based testing (Trail of Bits)

Writes and reviews property tests with Hypothesis, fast-check, proptest and others, and tells a wrong property from a real bug when one fails.

name: property-based-testingBy Trail of BitsChecked
View source on GitHub
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark

Install

Commands are pinned to commit 149d7b2, the version we read, wherever the install method supports it.

npx skills

Terminal
npx skills add trailofbits/skills@149d7b21f4067765b82e67029730b42d228ef4b4 --skill property-based-testing -a claude-code

Copies the skill into .claude/skills/ in this project, pinned to the reviewed commit.

Plugin marketplace

Claude Code prompt
/plugin marketplace add trailofbits/skills
/plugin install property-based-testing@trailofbits

Run inside Claude Code. Installs the whole property-based-testing plugin from its default branch, not the pinned commit.

What it does

Helps an agent write property tests, which check a rule over many generated inputs instead of a few hand-picked examples. The SKILL.md is short and centred on a property catalogue: roundtrip (decode(encode(x)) == x), inverse, oracle (new code matches a reference), idempotence, invariants, easy-to-verify outputs (is_sorted(sort(x))), commutativity, associativity and identity. It ranks them from weakest (“no crash”) to strongest (roundtrip or oracle) and tells the agent to assert the strongest one the code supports. It also names the two ways a property test can assert nothing: tautology, which recomputes the implementation, and vacuity, where assume() filters out nearly every input. Reference files cover generators, interpreting failures, reviewing existing property tests, refactoring for testability and the libraries per language: Hypothesis, fast-check, proptest, jqwik, rapid, and Echidna or Medusa for Solidity.

When to use it

Serialisers and parsers, normalisers, validators, numeric and decimal types, comparators and sort orders, data structures and smart-contract invariants. It also helps when a property test fails and you need to know whether the property or the code is wrong.

When to skip it

Coverage-guided fuzzing of binaries, mutation testing campaigns, static analysis and end-to-end UI tests; the description excludes all of them. Glue code with no clear rule to state is also a poor fit, and the skill says to report that honestly rather than write a “no crash” test.

Try it

Add property-based tests with Hypothesis for money.py. Find the strongest
properties the Money type supports (roundtrip through to_string/parse,
addition associativity, currency mismatch errors) and explain why each one
can fail.

What it can touch

Bundles scripts
No
Pre-approved tools
None declared
Needs
A property-testing library for your language
Client-specific fields
effort

claude.ai and the Claude API reject uploads that use fields outside the open spec or names containing "claude" or "anthropic", so this skill needs editing before you upload it there.

Its instructions steer what your agent does, and it may have changed since the commit we read. How to check a skill.

Instructions and references only. It writes test files and runs your test suite, and you need the property-testing library installed. No allowed-tools. It sets effort: low, a field outside the open spec. Content is licensed CC-BY-SA-4.0.

At commit 149d7b2 the SKILL.md is 68 lines long. Alongside it:

  • agents/ (1 entry)
  • assets/ (1 entry)
  • references/ (5 entries)
  • README.md

Alternatives

Mutation testing to measure whether the new tests catch more, and TDD or test-driven development for example-based tests written first.

SKILL.md

The file exactly as published at the reviewed commit, reproduced under its CC-BY-SA-4.0 licence.

plugins/property-based-testing/skills/property-based-testing/SKILL.md
---
name: property-based-testing
effort: low
description: "Writes, reviews, and debugs property-based tests — Hypothesis, fast-check, proptest, jqwik, rapid, and Echidna or Medusa for Solidity invariants. Use whenever tests should cover a whole input domain instead of a hand-picked list of examples: encode/decode and serialize/deserialize pairs, parsers, canonicalizers and normalizers, validators, numeric and Decimal types, comparators and sort order, data structures, and smart-contract state invariants. Also use when adding cases to an existing @given, fast-check, or proptest suite, when judging whether existing property tests assert anything real, and when a generator has shrunk a counterexample and you need to tell a wrong property from a genuine bug. Not for coverage-guided binary fuzzing (libFuzzer, AFL), mutation-testing campaigns, static analysis, benchmarking, or end-to-end UI tests."
---

# Property-Based Testing

An example test asserts one point. A property asserts a rule over the whole input
domain and lets the generator hunt for the counterexample. That trade is worth making
when the code has an algebraic shape — an inverse, an invariant, an oracle — and not
otherwise. Code with no such shape gets example tests; saying so is a valid outcome.

Check first whether the shape is missing or merely buried. A calculation wrapped in I/O,
a string built by concatenation, an in-place mutation — each has a property and no seam
to assert it through. See [references/refactoring.md](references/refactoring.md) before
concluding there is nothing to assert.

## Property catalog

| Property | Formula | Where it applies |
|---|---|---|
| Roundtrip | `decode(encode(x)) == x` | Serialization, conversion pairs |
| Inverse | `f(g(x)) == x` | encrypt/decrypt, compress/decompress |
| Oracle | `new(x) == reference(x)` | Optimization, refactoring, reimplementation |
| Idempotence | `f(f(x)) == f(x)` | Normalization, formatting, sorting |
| Invariant | Holds before and after | Any transformation, contract state |
| Easy to verify | `is_sorted(sort(x))` | Complex algorithms with cheap checkers |
| Commutativity | `f(a, b) == f(b, a)` | Binary and set operations |
| Associativity | `f(f(a,b), c) == f(a, f(b,c))` | Combining operations |
| Identity | `f(x, e) == x` | Operations with a neutral element |

Strength ordering, weakest to strongest:
`no crash → type preservation → invariant → idempotence → roundtrip / oracle`.

Assert the strongest property the code supports. "No crash" alone rarely justifies the
dependency — if that is all you can find, either a small rearrangement exposes something
stronger, or the honest report is that this code is a poor PBT candidate. Rule out the
first before settling for the second.

## The two ways a property test asserts nothing

- **Tautology.** `assert add(a, b) == a + b` restates the implementation; no bug they
  share can fail it. Pick a property that constrains the function without recomputing
  it. Note the exception: `f(x) == f(x)` is a genuine determinism property when `f`
  is not obviously pure — serializers over dicts or sets, hashing, anything reading
  the clock.
- **Vacuity.** `assume()` that filters out nearly every input passes without
  exercising anything, and self-contradictory `assume()` passes having run zero cases.
  Push constraints into the strategy so the generator produces valid inputs directly.

## Where to look next

Load the one that matches the task in front of you:

| Task | File |
|---|---|
| Writing new tests, designing strategies | [references/generating.md](references/generating.md) |
| The code has no property to assert yet | [references/refactoring.md](references/refactoring.md) |
| Reviewing existing property tests | [references/reviewing.md](references/reviewing.md) |
| A property test just failed | [references/interpreting-failures.md](references/interpreting-failures.md) |
| Library choice, Echidna and Medusa | [references/libraries.md](references/libraries.md) |

## Introducing PBT to a project that lacks it

If the project already uses a PBT library, just write the tests in it. If it does not,
adding one is a dependency decision that belongs to the user — offer it once with the
specific property you would write, and take the answer either way.
  • Mutation testing (Trail of Bits)

    Sets up mutation testing campaigns with Trail of Bits' mewt or muton, reads surviving mutants and hunts the bugs that weak tests let through.

    Checked at 149d7b2

  • TDD (Matt Pocock)

    Matt Pocock's short test-driven development skill: agree the seams first, then write one failing test and one minimal fix at a time, with notes on mocks.

    Engineering workflowChecked at abeeaf9

  • Playwright CLI

    Microsoft's skill for driving a real browser with playwright-cli: snapshots, clicks, form input, network mocking, tracing and turning sessions into tests.

    MicrosoftChecked at c872a33

  • Test automation

    Automating functional, API and end-to-end checks so every change gets tested.

    SkillBeginner