Back to Skills

hypothesis-testing

verified

Property-based testing with Hypothesis for discovering edge cases and validating invariants. Use when testing code with many possible inputs, verifying mathematical properties, testing serialization round-trips, or finding edge cases that example-based tests miss.

View on GitHub

Marketplace

laurigates-plugins

laurigates/claude-plugins

Plugin

testing-plugin

testing

Repository

laurigates/claude-plugins
3stars

testing-plugin/skills/hypothesis-testing/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/laurigates/claude-plugins/blob/main/testing-plugin/skills/hypothesis-testing/SKILL.md -a claude-code --skill hypothesis-testing

Installation paths:

Claude
.claude/skills/hypothesis-testing/
Powered by add-skill CLI

Instructions

# Hypothesis Property-Based Testing

Automatically generate test cases to find edge cases and validate properties of your code.

## When to Use Hypothesis vs Example-Based Tests

| Use Hypothesis when... | Use example-based tests when... |
|------------------------|-------------------------------|
| Testing mathematical properties (commutative, associative) | Testing specific known edge cases |
| Many valid inputs need testing | Exact business logic with known values |
| Verifying serialization round-trips | Testing specific error messages |
| Finding edge cases you can't predict | Integration with external systems |
| Testing APIs with many parameters | Testing UI behavior |

## Installation

```bash
uv add --dev hypothesis pytest

# Optional extensions
uv add --dev hypothesis[numpy]   # NumPy strategies
uv add --dev hypothesis[django]  # Django model strategies
```

## Configuration

```toml
# pyproject.toml
[tool.hypothesis]
max_examples = 200
deadline = 1000

[tool.hypothesis.profiles.dev]
max_examples = 50
deadline = 1000

[tool.hypothesis.profiles.ci]
max_examples = 500
deadline = 5000
verbosity = "verbose"
```

```python
# Activate profile
from hypothesis import settings, Phase
settings.load_profile("ci")  # Use in conftest.py
```

## Basic Usage

```python
from hypothesis import given, example, assume
import hypothesis.strategies as st

# Test a property
@given(st.integers(), st.integers())
def test_addition_commutative(a, b):
    assert a + b == b + a

# Add explicit edge cases
@given(st.integers())
@example(0)
@example(-1)
@example(2**31 - 1)
def test_with_explicit_examples(x):
    assert process(x) is not None

# Skip invalid inputs
@given(st.floats(allow_nan=False, allow_infinity=False),
       st.floats(allow_nan=False, allow_infinity=False))
def test_safe_divide(a, b):
    assume(b != 0)
    result = a / b
    assert isinstance(result, float)
```

## Essential Strategies

```python
import hypothesis.strategies as st

# Primitives
st.integers()         

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
5199 chars