property-based-testing
Improves software reliability by using property-based testing for serialization, parsers, and state invariants.
Install
mkdir -p .claude/skills/property-based-testing && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/6273" && unzip -o skill.zip -d .claude/skills/property-based-testing && rm skill.zipInstalls to .claude/skills/property-based-testing
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Provides guidance for property-based testing across multiple languages and smart contracts. Use when writing tests, reviewing code with serialization/validation/parsing patterns, designing features, or when property-based testing would provide stronger coverage than example-based tests.Key capabilities
- →Identify opportunities for round-trip property testing
- →Map data invariants for custom structures
- →Generate test strategies for serialization/deserialization logic
- →Prioritize coverage based on function volatility
How it works
Analyzes code patterns for properties like round-trip equality or idempotence to structure tests based on behavior rather than inputs.
Inputs & outputs
When to use property-based-testing
- →Validate encode/decode pairs
- →Test pure transformation functions
- →Verify smart contract state invariants
- →Check parser robustness
About this skill
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 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 + brestates 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 whenfis 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-contradictoryassume()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 |
| The code has no property to assert yet | references/refactoring.md |
| Reviewing existing property tests | references/reviewing.md |
| A property test just failed | references/interpreting-failures.md |
| Library choice, Echidna and Medusa | 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.
When not to use it
- →Testing code with complex side effects
- →Simple CRUD operations without internal logic
Limitations
- →Requires writing logic that can be mathematically verified
- →Overhead for simple functions
How it compares
It prioritizes property invariants over hardcoded examples, yielding better coverage for edge cases.
Compared to similar skills
property-based-testing side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| property-based-testing (this skill) | 1 | 3mo | No flags | Advanced |
| netalertx-code-standards | 1 | 4mo | Review | Intermediate |
| review-implementation | 0 | 6mo | Review | Intermediate |
| test | 0 | 2mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by trailofbits
View all by trailofbits →You might also like
netalertx-code-standards
netalertx
NetAlertX coding standards and conventions. Use this when writing code, reviewing code, or implementing features.
review-implementation
karrioapi
Perform a fresh-context review of completed work against PRD, tests, and conventions.
test
FalkorDB
Run FalkorDB's test suites - Rust unit tests, Python e2e/function/MVCC/concurrency tests, openCypher TCK compliance tests, and flow tests. Use when asked to run, narrow down, or debug a failing test, or to decide which suite covers a change.
api-test-generator
mikopbx
Генерация полных Python pytest тестов для REST API эндпоинтов с валидацией схемы. Использовать при создании тестов для новых эндпоинтов, добавлении покрытия для CRUD операций или валидации соответствия API с OpenAPI схемами.
generate-validation-notebook
monte-carlo-data
Generate SQL validation notebooks for dbt changes. Pass a GitHub PR URL or local dbt repo path.
mock-interviewer
std2main
模拟硅谷大厂 Senior Engineer 进行技术面试,支持语音交互和实时代码审计。