From aj-geddes-useful-ai-prompts-4
Designs property-based tests that verify code invariants across automatically generated inputs, using frameworks like Hypothesis, fast-check, and junit-quickcheck.
How this skill is triggered — by the user, by Claude, or both
Slash command
/aj-geddes-useful-ai-prompts-4:property-based-testingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- [Overview](#overview)
Property-based testing verifies that code satisfies general properties or invariants for a wide range of automatically generated inputs, rather than testing specific examples. This approach finds edge cases and bugs that example-based tests often miss.
Minimal working example:
# test_string_operations.py
import pytest
from hypothesis import given, strategies as st, assume, example
def reverse_string(s: str) -> str:
"""Reverse a string."""
return s[::-1]
class TestStringOperations:
@given(st.text())
def test_reverse_twice_returns_original(self, s):
"""Property: Reversing twice returns the original string."""
assert reverse_string(reverse_string(s)) == s
@given(st.text())
def test_reverse_length_unchanged(self, s):
"""Property: Reverse doesn't change length."""
assert len(reverse_string(s)) == len(s)
@given(st.text(min_size=1))
def test_reverse_first_becomes_last(self, s):
"""Property: First char becomes last after reverse."""
reversed_s = reverse_string(s)
assert s[0] == reversed_s[-1]
assert s[-1] == reversed_s[0]
// ... (see reference guides for full implementation)
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Hypothesis for Python | Hypothesis for Python |
| fast-check for JavaScript/TypeScript | fast-check for JavaScript/TypeScript |
| junit-quickcheck for Java | junit-quickcheck for Java |
npx claudepluginhub joshuarweaver/cascade-code-languages-misc-1 --plugin aj-geddes-useful-ai-prompts-4Generates property-based tests using fast-check (TypeScript/JavaScript with Vitest) and Hypothesis (Python) to find edge cases, verify properties like roundtrips and invariants.
Generates property-based and generative tests with fast-check, hypothesis, and automatic shrinking to discover edge cases missed by example-based tests.
Guides property-based testing for serialization, validation, normalization, and pure functions with property catalog, pattern detection, and library references.