16. Property-Based Testing with Hypothesis
Date: 2025-10-13Status
AcceptedCategory
Testing & QualityContext
Traditional unit tests check specific examples:- Negative numbers
- Zero values
- Very large numbers
- Unicode in strings
Decision
Use Hypothesis for property-based testing to discover edge cases automatically.Example
Consequences
Positive
- Edge Case Discovery: Finds bugs unit tests miss
- Higher Confidence: Tests properties, not examples
- Less Test Code: One property test replaces many examples
- Regression Prevention: Generated cases saved on failure
Negative
- Slower Tests: 100 cases per test vs 1
- Learning Curve: Property thinking vs example thinking
- Flaky Tests: Random generation can cause intermittent failures
Usage
27+ property tests covering:- LLM factory fallback logic
- Authentication providers
- Session management
- Role mapping
References
- Tests:
tests/property/ - Dependency:
pyproject.toml:66-hypothesis>=6.100.0