property-based-testing▌
aj-geddes/useful-ai-prompts · updated Apr 8, 2026
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.
Property-Based Testing
Table of Contents
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.
When to Use
- Testing algorithms with mathematical properties
- Verifying invariants that should always hold
- Finding edge cases automatically
- Testing parsers and serializers (round-trip properties)
- Validating data transformations
- Testing sorting, searching, and data structure operations
- Discovering unexpected input combinations
Quick Start
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)
Reference Guides
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 |
Best Practices
✅ DO
- Focus on general properties, not specific cases
- Test mathematical properties (commutativity, associativity)
- Verify round-trip encoding/decoding
- Use shrinking to find minimal failing cases
- Combine with example-based tests for known edge cases
- Test invariants that should always hold
- Generate realistic input distributions
❌ DON'T
- Test properties that are tautologies
- Over-constrain input generation
- Ignore shrunk test failures
- Replace all example tests with properties
- Test implementation details
- Generate invalid inputs without constraints
- Forget to handle edge cases in generators
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.6★★★★★26 reviews- ★★★★★Dhruvi Jain· Dec 28, 2024
Useful defaults in property-based-testing — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Aanya Desai· Dec 16, 2024
I recommend property-based-testing for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Oshnikdeep· Nov 19, 2024
property-based-testing has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Michael Thompson· Nov 7, 2024
Solid pick for teams standardizing on skills: property-based-testing is focused, and the summary matches what you get after install.
- ★★★★★Aanya Dixit· Nov 3, 2024
Registry listing for property-based-testing matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Emma Jain· Oct 26, 2024
property-based-testing has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Michael Robinson· Oct 22, 2024
property-based-testing reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Ganesh Mohane· Oct 10, 2024
Solid pick for teams standardizing on skills: property-based-testing is focused, and the summary matches what you get after install.
- ★★★★★Ama Chen· Sep 17, 2024
Keeps context tight: property-based-testing is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Mia Lopez· Sep 13, 2024
I recommend property-based-testing for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
showing 1-10 of 26