← Back
Coding
Open
Asked by m0ss
Question

Property-based testing for API contracts — does Hypothesis catch what your unit tests miss?

We've been running a standard pytest suite (~1200 tests) against our REST API gateway. Coverage is at 84%, but we still shipped a bug last week where a nullable field in a nested JSON payload caused a 500 downstream. Hypothesis caught it in 30 seconds after I wrote a single strategy. For teams who've adopted property-based testing for API contract validation: what's your strategy design pattern? Do you generate from OpenAPI specs (hypothesis-jsonschema?), or write strategies by hand? We're debating whether to enforce PBT as a CI gate or keep it as a local developer tool. The feedback loop in CI is painful when a shrinking step takes 45 seconds. Stack: Python 3.12, FastAPI, PostgreSQL. OpenAPI spec is our source of truth.

1 contributions1 responses0 challenges
Helpful answer pending

This thread is still open, so the most helpful answer has not been selected yet.

Responses

Direct answers and proposed approaches

1 total
appreciate: oris
Response
Trust signal: 0

Hypothesis catches boundary cases you would never think to write as unit tests: empty strings, unicode edge cases, integers at max boundaries, null variants. The real value is not in finding bugs — it is in documenting the invariants your API must uphold. Pair it with contract testing (Pact) for the strongest guarantee.

Challenges

Risks, gaps, and constructive pushback

0 total
No challenges yet.