Testing for Beginners

9 articles across 3 parts — read in order.

I — Core Concepts

2 articles
  1. 01Why Testing Matters: The Cost of Bugs and the Confidence to ChangeWhy bugs found late cost so much more to fix, the idea of confidence to change, testing's honest limits, and the big picture of the testing pyramid we'll build throughout this series.
  2. 02Anatomy of a Good Test: AAA, Test Doubles, and the FIRST PrinciplesThe Arrange-Act-Assert pattern, what actually distinguishes unit, integration, and E2E tests, the vocabulary of test doubles (dummy, stub, fake, mock, spy), and the FIRST principles as a yardstick for a healthy test.

II — Hands-On Practice

6 articles
  1. 03Hands-On: Your First Unit Test with PytestPytest's install and basic conventions, writing your first unit test for pure functions in app/security.py, testing negative cases, and marking tests so fast and slow ones can be run separately.
  2. 04Hands-On: Fixtures & Dependency OverrideWriting pytest fixtures with yield, why tests use in-memory SQLite instead of a real Postgres, swapping FastAPI dependencies via dependency_overrides, and the lifespan trap that reaches for a real database.
  3. 05Hands-On: Parametrization & Table-Driven TestsAvoiding test duplication with pytest.mark.parametrize, giving each case a clear ID, boundary testing at the edges of a validation rule, and when NOT to reach for parametrization.
  4. 06Hands-On: Mocking & Test DoublesWhy external services must never be called for real during a test, mocking with pytest-mock, the "patch where it's used" rule, and verifying interactions with assert_called_once_with.
  5. 07Hands-On: Test Coverage & Its LimitsMeasuring coverage with pytest-cov, why code bypassed via a dependency override shows up as uncovered, why 100% coverage isn't the goal, and a quick look at mutation testing.
  6. 08Hands-On: TDD — Red, Green, RefactorBuilding a task search feature from scratch through the Test-Driven Development cycle — write a test that's guaranteed to fail (Red), the simplest code that makes it pass (Green), then clean up without changing behavior (Refactor).

III — Best Practices

1 article
  1. 09Best Practices & Next StepsA checklist for a healthy test suite, common mistakes like flaky tests and over-mocking, and a roadmap for what's next — property-based testing, mutation testing, contract testing, and running tests automatically in CI.