Loading...
Loading...
Property-based testing with fast-check (TypeScript/JavaScript) and Hypothesis (Python). Generate test cases automatically, find edge cases, and test mathematical properties. Use when user mentions property-based testing, fast-check, Hypothesis, generating test data, QuickCheck-style testing, or finding edge cases automatically.
npx skill4agent add laurigates/claude-plugins property-based-testing| Use this skill when... | Use another skill instead when... |
|---|---|
| Testing mathematical properties (commutative, associative) | Writing specific example-based unit tests |
| Testing encode/decode roundtrips | Setting up test runner configuration |
| Finding edge cases automatically | Doing E2E browser testing |
| Validating data transformations and invariants | Analyzing test quality or smells |
| Testing API contracts with generated data | Running mutation testing |
# Using Bun
bun add -d fast-check
# Using npm
npm install -D fast-checkimport { test } from 'vitest'
import * as fc from 'fast-check'
// Property-based test
test('reverse twice returns original - property based', () => {
fc.assert(
fc.property(
fc.array(fc.integer()), // Generate random arrays of integers
(arr) => {
expect(reverse(reverse(arr))).toEqual(arr)
}
)
)
})
// fast-check automatically generates 100s of test cases!| Generator | Description |
|---|---|
| Any integer (with optional min/max) |
| Natural numbers (>= 0) |
| Floating-point numbers |
| Any string (with optional length) |
| Email format strings |
| Arrays of arbitrary type |
| Object with typed fields |
| Boolean values |
| Pick from options |
| Fixed-size tuples |
| Union types |
| Value or null |
| Date objects |
| Property | Pattern | Example |
|---|---|---|
| Roundtrip | | encode/decode, serialize/parse |
| Idempotence | | sort, normalize, format |
| Commutativity | | add, merge, union |
| Associativity | | add, concat |
| Identity | | multiply by 1, add 0 |
| Inverse | | encrypt/decrypt |
fc.assert(property, {
numRuns: 1000, // Run 1000 tests (default: 100)
seed: 42, // Reproducible tests
endOnFailure: true, // Stop after first failure
})fc.pre(b !== 0) // Skip cases where b is 0# Using uv
uv add --dev hypothesis
# Using pip
pip install hypothesisfrom hypothesis import given, strategies as st
@given(st.lists(st.integers()))
def test_reverse_twice_property(arr):
assert reverse(reverse(arr)) == arr
# Hypothesis automatically generates 100s of test cases!| Strategy | Description |
|---|---|
| Any integer (with optional bounds) |
| Floating-point numbers |
| Any string (with optional size) |
| Byte strings |
| Lists of given strategy |
| Unique value sets |
| Dictionaries |
| Boolean values |
| Pick from options |
| Fixed-size tuples |
| Union types |
| Date/time values |
| Build objects from strategies |
from hypothesis import given, settings, strategies as st
@settings(max_examples=1000, deadline=None)
@given(st.lists(st.integers()))
def test_with_custom_settings(arr):
assert sort(arr) == sorted(arr)from hypothesis import assume
assume(b != 0) # Skip cases where b is 0RuleBasedStateMachine| Context | Command |
|---|---|
| Quick TS test | |
| Quick Python test | |
| CI TS test | |
| CI Python test | |
| Reproducible | |
| Fast iteration | |
vitest-testingpython-testingtest-quality-analysismutation-testing