GuideIntermediate

Testing Backend Applications Guide

Learn backend testing end to end: pytest fundamentals, fixtures, mocking with unittest.mock and pytest-mock, integration testing with test databases and factories, E2E testing with the FastAPI TestClient, coverage with pytest-cov, the TDD workflow, and CI with GitHub Actions. Build a production-grade test suite with 80%+ coverage.

48
lessons
6
modules
English · Spanish
available in
Yes
certificate
Included in the Club
access
NIEVA

Outcomes

What you'll be able to do

  • Pytest Fundamentals: Fixtures, parametrize, markers, conftest.py, plugins
  • Unit Testing: Functions, classes, dependency isolation, advanced assertions
  • Mocking: unittest.mock, pytest-mock, patching, side effects, spec
  • Integration Testing: Test databases, SQLAlchemy fixtures, factories with factory_boy
  • E2E Testing: FastAPI TestClient, full workflows, auth testing
  • Coverage: pytest-cov, coverage reports, thresholds, branch coverage
  • TDD: Red → Green → Refactor, test-first development
  • CI: GitHub Actions, test pipeline, automated coverage checks

Before you start

What you need to bring

Requirements and materials

  • FastAPI Fundamentals and Advanced completed (#6-#7)
  • PostgreSQL & SQLAlchemy Guide completed (#8)
  • Authentication & Authorization Guide completed (#9)
  • A working API with endpoints, models and auth

Content

The syllabus, module by module

Open any of them to see its lessons.

  • Module 1: Pytest Fundamentals
  • Pytest vs unittest, setup and your first test
  • Fixture fundamentals and scopes
  • Parametrize: coverage without duplication
  • Markers and filtering
  • conftest.py: professional organization
  • Project structure and essential plugins
  • Project: your first structured tests

  • Module 2: Unit Testing and Mocking
  • Pure unit testing: functions without dependencies
  • `unittest.mock` fundamentals
  • pytest-mock: the `mocker` fixture
  • `side_effect`: complex behaviors
  • `spec` and `autospec`: mocks that respect the interface
  • Service + Repository pattern with mocks
  • Project: unit tests with mocks for business logic

  • Module 3: Integration Testing
  • Test database: SQLite in-memory vs real Postgres
  • SQLAlchemy fixtures: the canonical pattern
  • factory_boy: test data that scales
  • Repository tests against a real DB
  • Service tests with a DB + external APIs
  • Mocking external APIs with respx and responses
  • Project: a complete integration test suite

  • Module 4: E2E with FastAPI TestClient
  • TestClient setup + `dependency_overrides`
  • Full end-to-end CRUD
  • `httpx.AsyncClient` for async tests
  • Complete auth flows
  • Error responses: 400, 401, 403, 404, 422
  • Pagination, filtering, query params, headers
  • Project: a complete E2E test suite

  • Module 5: Coverage, TDD and CI
  • pytest-cov: setup and reports
  • Reading coverage: line vs branch
  • Coverage thresholds and exclusions
  • TDD: red → green → refactor
  • GitHub Actions: basic workflow
  • PR checks, coverage badges, reports
  • Project: CI pipeline with tests + coverage

  • Module 6: Project — A Complete Test Suite
  • Setup + project selection
  • The test strategy document (TESTING.md)
  • Building the unit test suite
  • Building an integration test suite
  • Building an E2E test suite
  • Coverage + CI pipeline integration
  • Final report + portfolio piece

Where it fits

This guide is part of something bigger

It's studied inside these programs, with support and dates.

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!