GuideIntermediate

Property-Based and Advanced Testing

Learn property-based testing with Hypothesis: instead of writing tests for the examples you thought of, you define a property (an invariant) that must hold for EVERY input, and let Hypothesis generate and search for the case that breaks it. This guide covers your first test with `@given` and basic strategies, how to describe the input space with composite strategies (`@st.composite`), the patterns for finding properties (invariant, round-trip, oracle, metamorphic, idempotence), shrinking (how Hypothesis reduces a failing case to the minimal example), stateful property-based testing with `RuleBasedStateMachine`, and a set of additional advanced techniques (parametrized fixtures, a taste of mutation testing, fuzzing). It closes with a capstone project: find and fix a real Reservo bug using property-based testing.

64
lessons
8
modules
English · Spanish
available in
Yes
certificate
Free
access
NIEVA

Outcomes

What you'll be able to do

  • Distinguish example-based tests from property-based testing: proving an invariant for EVERY input, not just the ones you imagined
  • Write your first Hypothesis test using `@given` and basic strategies (`st.integers`, `st.floats`, `st.text`, `st.datetimes`)
  • Describe the input space with composite strategies: `@st.composite`, `map`/`filter`/`flatmap`, and `assume()`
  • Recognize the patterns for finding properties: invariant, round-trip, oracle, metamorphic, and idempotence
  • Read shrinking: how Hypothesis reduces a failing case to the minimal example, and pin regressions with `@example`
  • Model a stateful system and verify invariants across sequences of operations with `RuleBasedStateMachine`
  • Learn additional advanced techniques: parametrized fixtures, a taste of mutation testing, and how fuzzing relates to property-based testing
  • Find and fix a real Reservo bug using property-based testing as a capstone project

Before you start

What you need to bring

It's for you if...

  • Devs who already write example-based tests with pytest and want to catch bugs those tests miss
  • Devs with pure-logic functions (calculations, validations, transformations) where covering the full input space matters
  • Devs who already have a solid grasp of testing fundamentals and want to move into advanced techniques

Requirements and materials

  • pytest, asserts, basic fixtures, and simple parametrize (or the Testing Fundamentals & TDD Guide completed)
  • Python 3.10+ with pip to install the `hypothesis` library
  • Comfortable reading pure-logic functions in Python

Content

The syllabus, module by module

Open any of them to see its lessons.

Common questions

What people usually ask

Start whenever you like

Reviews

What students say

These reviews are from enrolled students who completed at least 50% of the course. We moderate reviews only on content grounds (spam, offensive language, personal data), never for being critical or negative.

No approved reviews yet.

Be the first to share your experience!