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
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.
- 1. Module introduction: from the example to the property
- 2. The limit of the example-based test
- 3. What a property is (an invariant)
- 4. The properties hidden in Reservo
- 5. Property against example, side by side
- 6. Why machines find the weird cases
- 7. The cost and the benefit
- 8. Mini-project: three properties of `refund_cents` checked by hand
- 1. Module introduction: from the by-hand loop to Hypothesis
- 2. Install Hypothesis and your first green property
- 3. The `@given` decorator and your first Reservo property
- 4. Integer strategies and ranges
- 5. `st.floats` and its traps: `nan`, `inf` and rounding
- 6. Text and datetime strategies
- 7. Reading the falsifying example (`Failing test case`)
- 8. Mini-project: three properties of Reservo with `@given`
- 1. Module introduction: from a loose value to the whole input space
- 2. Strategies as values: ranges, `sampled_from` and `one_of`
- 3. Building objects with `st.builds`
- 4. `@st.composite`: assembling a coherent `Booking`
- 5. Transforming with `.map()`
- 6. `.filter()` and `assume()`: discarding what doesn't work
- 7. `.flatmap()` and dependent strategies
- 8. Mini-project: a strategy for valid bookings and a property over them
- 1. Module introduction: from the ugly counterexample to the minimal reproducer
- 2. What shrinking is and why it matters
- 3. Shrinking in action: a Reservo bug
- 4. Reading the minimal example
- 5. `@example` to nail a regression
- 6. The database of failures and determinism
- 7. `settings`: adjusting how many, how long and which phases
- 8. Mini-project: shrink a subtle Reservo bug
- 1. Module introduction: properties over sequences, not over one call
- 2. Why state changes everything
- 3. `RuleBasedStateMachine`: the minimal machine
- 4. `@rule` for `book` and `cancel`
- 5. `Bundle`: passing bookings between rules
- 6. `@invariant`: what must always hold
- 7. A sequence that breaks an invariant
- 8. Mini-project: model the Calendar and find a bug
- 1. Module introduction: the toolbox beyond Hypothesis
- 2. Indirect parametrize and `pytest.param`
- 3. Stacking parametrize: the cartesian product
- 4. Fixture factories
- 5. Parametrized fixtures and scope
- 6. Mutation testing by hand: does your suite catch bugs?
- 7. Fuzzing vs property-based
- 8. Mini-project: a fixture factory, a table and a mutant
- 1. Module introduction: the complete cycle of catching a bug
- 2. Choosing the suspicious function
- 3. Writing the first property
- 4. Watching it fail: the falsifying example
- 5. Shrinking to the minimum: the smallest reproducer
- 6. Diagnosing and fixing
- 7. Locking the bug with a regression `@example`
- 8. Project: find a real bug with property-based
Common questions
What people usually ask
No limit. It's a free guide: come in whenever you like, as often as you like.
No. Modules run from easier to harder, but you can jump to the one you need. Progress is saved per lesson.
Whatever is needed is listed under “What you need to bring”, above. If nothing is listed there, you can start from zero.
In the Club's WhatsApp group, and every two weeks there's a live with an instructor where questions get worked through.
Yes. It's issued automatically once you finish every lesson, with a verifiable code you can share on LinkedIn.
Start whenever you like
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!