Overview
This plugin provides intelligent guidance for writing property-based tests when Claude Code detects suitable patterns in your code. Instead of writing individual example tests, PBT tests properties that should always hold:- Roundtrip properties -
decode(encode(x)) == x - Idempotence -
f(f(x)) == f(x) - Invariants - Properties preserved across transformations
- Commutativity -
f(a, b) == f(b, a) - Oracle comparison -
new_impl(x) == reference(x)
The plugin automatically suggests PBT when it detects high-value patterns like serialization pairs, parsers, validators, or smart contract invariants.
When to Use
Automatic Detection Patterns
The plugin activates when detecting:Serialization Pairs
encode/decode, serialize/deserialize, toJSON/fromJSON, pack/unpackParsers
URL parsing, config parsing, protocol parsing, string-to-structured-data
Normalization
normalize, sanitize, clean, canonicalize, formatValidators
is_valid, validate, check_* (especially with normalizers)Data Structures
Custom collections with
add/remove/get operationsSmart Contracts
Solidity/Vyper contracts, token operations, state invariants, access control
Priority Matrix
| Pattern | Property | Priority |
|---|---|---|
| encode/decode pair | Roundtrip | HIGH |
| Pure function | Multiple | HIGH |
| Smart contract | State invariants | HIGH |
| Validator | Valid after normalize | MEDIUM |
| Sorting/ordering | Idempotence + ordering | MEDIUM |
| Normalization | Idempotence | MEDIUM |
| Builder/factory | Output invariants | LOW |
When NOT to Use
Supported Languages
The plugin provides language-specific guidance for:- General Purpose
- Smart Contracts
- Python - Hypothesis
- JavaScript/TypeScript - fast-check
- Rust - proptest, quickcheck
- Go - rapid, gopter
- Java - jqwik
- Scala - ScalaCheck
- Haskell - QuickCheck
- F# - FsCheck
- Erlang/Elixir - PropEr, StreamData
references/libraries.md for complete library documentation.
Property Catalog
Core Properties
Roundtrip
Roundtrip
Formula:
decode(encode(x)) == xWhen to use: Serialization, conversion pairs, compress/decompressExample:Idempotence
Idempotence
Formula:
f(f(x)) == f(x)When to use: Normalization, formatting, sorting, deduplicationExample:Invariant
Invariant
Formula: Property holds before and after transformationWhen to use: Any transformation that preserves certain propertiesExample:
Commutativity
Commutativity
Formula:
f(a, b) == f(b, a)When to use: Binary operations, set operations, merge functionsExample:Oracle
Oracle
Formula:
new_impl(x) == reference(x)When to use: Optimization, refactoring, algorithm replacementExample:Inverse
Inverse
Formula:
f(g(x)) == xWhen to use: encrypt/decrypt, compress/decompress, add/removeExample:Property Strength Hierarchy
- Start with “no exception” as baseline
- Look for invariants that must hold
- Identify idempotence opportunities
- Seek roundtrip properties for paired operations
Quick Start Examples
Python (Hypothesis)
JavaScript/TypeScript (fast-check)
Rust (proptest)
Solidity (Echidna)
How Claude Suggests PBT
Existing PBT Library Detected
If the codebase already uses a PBT library, Claude will be direct:“This codebase uses Hypothesis. I’ll write property-based tests for this serialization pair using a roundtrip property.”
No PBT Library
If no library is detected, Claude offers it as an option:“I notice
encode_message/decode_message is a serialization pair. Property-based testing with a roundtrip property would provide stronger coverage than example tests. Want me to use that approach?”User Declines
If you decline, Claude will write good example-based tests without further prompting.Advanced Topics
Custom Generators
For complex domain types, the plugin provides guidance on writing custom generators that produce valid inputs while maintaining coverage.Shrinking
When tests fail, PBT libraries automatically find the smallest failing input. The plugin includes guidance on interpreting and acting on shrunk failures.State Machine Testing
For stateful systems (databases, caches, smart contracts), the plugin provides patterns for modeling state transitions as properties.Performance Properties
Beyond correctness, test performance properties like:- Output size bounded by input size
- Linear time complexity
- Memory usage within limits
Antipatterns to Avoid
Rationalizations to Reject
The plugin enforces quality by rejecting these shortcuts:- “Example tests are good enough” - If serialization/parsing/normalization is involved, PBT finds edge cases examples miss
- “The function is simple” - Simple functions with complex input domains benefit most from PBT
- “We don’t have time” - PBT tests are often shorter than comprehensive example suites
- “It’s too hard to write generators” - Most libraries have excellent built-in strategies
- “No crash means it works” - “No exception” is the weakest property; push for stronger guarantees
Integration with Other Plugins
- Spec-to-Code Compliance - Verify implementation matches specification with property tests
- Testing Handbook Skills - Combine with fuzzing for comprehensive coverage
- Constant-Time Analysis - Test timing properties in crypto code
Resources
The plugin includes detailed reference documentation:references/generating.md- Test generation patterns and examplesreferences/strategies.md- Custom input generator guidancereferences/design.md- Property-Driven Development approachreferences/refactoring.md- Making code testable with propertiesreferences/reviewing.md- Quality checklist for existing testsreferences/interpreting-failures.md- Failure analysis and debuggingreferences/libraries.md- Complete library documentation by language
Examples from the Wild
Parser Testing
URL parser tested with 10,000 random URLs finds edge case with IPv6 zone IDs that example tests missed
Serialization Bug
MessagePack encoder/decoder roundtrip test finds corruption on 65536-byte boundary
Smart Contract
Token invariant testing discovers reentrancy vulnerability in balance update logic
Normalization
Unicode normalization tested with random strings finds non-idempotent case with combining characters
Author: Henrik Brodin (Trail of Bits)Version: 1.1.0