Free course · 11 lessons · Intermediate

Testing in Practice

Write tests that catch real bugs without slowing teams down: a testing strategy across unit, integration and end-to-end levels, pytest fixtures and parametrisation, test doubles without over-mocking, integration tests against a real database, property-based testing with Hypothesis, API tests through the HTTP layer, consumer-driven contract tests, end-to-end tests with Playwright, fixing flaky tests, and branch coverage in CI. Every example is real code run with pytest.

Start the course

1. Foundations: Strategy, pytest and Test Doubles

What to test and at which level, pytest fixtures and parametrisation, test doubles without over-mocking, integration tests against a real database, and property-based testing.

  1. A Testing Strategy That Pays Off — Decide what to test at which level (unit, integration, end-to-end), write clear tests with arrange-act-assert, and test behaviour rather than implementation.
  2. pytest Fixtures, Parametrisation and Markers — Share setup with fixtures (including scopes and teardown), cover many cases with parametrize, and organise suites with markers.
  3. Test Doubles: Fakes, Stubs and Mocks Without Over-Mocking — Replace slow or external dependencies with fakes and mocks at system boundaries, and avoid tests that only check your mocks.
  4. Integration Tests Against a Real Database — Test data-access code against a real SQL engine with schema setup, per-test transactions that roll back, and checks that constraints hold.
  5. Property-Based Testing with Hypothesis — Let Hypothesis generate hundreds of inputs to check properties that must always hold, find edge cases you didn't think of, and shrink failures.

2. Testing APIs, Contracts and User Journeys

API tests through the HTTP layer, consumer-driven contract tests, end-to-end tests with Playwright, fixing flaky tests, and coverage in CI.

  1. Testing HTTP APIs Through the Framework — Test web APIs through their HTTP layer with FastAPI's TestClient: status codes, validation errors, authentication and overridden dependencies.
  2. Consumer-Driven Contract Tests — Catch breaking API changes before deployment by checking the provider against the fields and types its consumers actually use.
  3. End-to-End Tests with Playwright — Drive a real browser through critical user journeys with Playwright, using role-based locators and auto-waiting assertions instead of sleeps.
  4. Finding and Fixing Flaky Tests — Diagnose tests that pass and fail without code changes, caused by time, ordering, shared state and randomness, and fix them for good.
  5. Coverage, Test Speed and Tests in CI — Measure branch coverage to find untested logic, set sensible thresholds, and organise fast and slow test stages in CI.

3. Capstone

Design a test strategy for a real system.

  1. Capstone: A Test Strategy for a Checkout Service — Design the test strategy for an e-commerce checkout: levels, data, external dependencies, end-to-end journeys, CI and flakiness policy.

Was this page helpful?