Module 5: Coverage and Edge Cases

Module 5: Coverage and Edge Cases

Module 5: Coverage and Edge Cases

Capsule overview

Your tests pass. Your feature works. The TDD cycle was successful. But there's an uncomfortable question you haven't answered: which tests did you NOT write?

The tests you write are the scenarios you imagine. And humans are systematically bad at imagining edge cases. The empty input, the unexpected None, the integer at MAX_INT, the Unicode string of 4 concatenated emojis — those are the scenarios that cause bugs in production, and they're exactly the ones your mind dismisses as "that never happens."

This module attacks that blind spot with two tools: coverage tells you quantitatively which code isn't being executed during your tests (the map), and edge case discovery with Claude Code helps you qualitatively find the scenarios you never imagined (the territory). Claude Code doesn't have the same cognitive biases — it can generate 15 edge cases where you'd have thought of 3.


Module Context

Where are we?

This is Module 5 — the second of Phase 2 (Testing Workflows).

What you already know:

  • ✅ Spec-first methodology and TDD with AI (Phase 1)
  • ✅ Unit tests, integration tests, E2E tests (Phase 1)
  • ✅ The complete TDD workflow: red-green-refactor (Module 4)

What's missing: Measuring the quality of your test suite and discovering what you aren't testing.

Where are we headed?

Phase 1: TDD Fundamentals with AI ✅
├── Modules 1-3: ✅ Completed

Phase 2: Testing Workflows
├── Module 4: ✅ The complete TDD workflow
├── Module 5: ← YOU ARE HERE — Coverage and edge cases
└── Module 6: → Mocking, fixtures, validation loops

Phase 3: Final Project
├── Module 7: → Professional testing strategy
└── Module 8: → Capstone project (target: ≥90% coverage)

This module prepares you directly for the final project, where the target is ≥90% coverage for the whole application.


Professional Objective

Measure, interpret and improve test coverage, and use Claude Code to discover edge cases you'd never have found on your own.

By the end of this module you'll be able to:

  • ✅ Use pytest-cov to generate coverage reports (line, branch, function)
  • ✅ Interpret a report: what an uncovered line means and whether it matters
  • ✅ Identify coverage gaps and generate tests with Claude Code to close them
  • ✅ Use specific prompts for edge case discovery (null, boundary, types, unicode)
  • ✅ Apply boundary testing: limit values in numeric inputs, strings, lists
  • ✅ Test error paths: exceptions, fallbacks, error messages
  • ✅ Use property-based testing with hypothesis to discover problematic inputs
  • ✅ Achieve ≥90% coverage on an existing module

Module Progression

Module Map

CapsuleTopicWhat you'll learn
02pytest-cov and coverage reportsInstalling, configuring, running pytest-cov. Reading line, branch, function coverage reports
03Interpreting coverageWhat the numbers mean. Uncovered lines. Branch coverage vs line coverage. 100% as a trap
04Edge cases with Claude CodePrompts to discover edge cases. Systematic categories. Claude Code as a thinking amplifier
05Boundary value analysis and property testingTesting limit values. Property-based testing with hypothesis. The complement to prompts
06Project: A suite with 90%+ coverageReceive existing code → measure → identify gaps → generate tests → reach ≥90%

Learning flow

First you'll master the tool (capsule 02): pytest-cov to measure coverage. Knowing how to measure is the first step to improving.

Then you'll understand what the numbers mean (capsule 03): interpreting reports, understanding the difference between line and branch coverage, and why 100% coverage doesn't mean bug-free code.

Next you'll learn edge case discovery (capsule 04): using Claude Code with specific prompts to find the scenarios you didn't imagine. This is where AI shines — it can analyze a function and generate complete categories of edge cases.

Capsule 05 introduces boundary testing and property-based testing: limit values and hypothesis as a complement. Where your prompts cover the known, hypothesis discovers the unknown.

In the project (capsule 06) you'll apply it all: measure, identify, generate, measure again. An iterative loop until you reach ≥90% coverage.


Project Connection

This module's project: A suite with 90%+ coverage

You'll receive existing code (a data processing module) with no tests or with minimal tests. Your job:

  1. Measure the current coverage (probably 0% or <30%)
  2. Identify the most critical gaps
  3. Use Claude Code to generate tests that close the gaps
  4. Discover edge cases with specific prompts
  5. Use hypothesis for property-based testing
  6. Iterate until you reach ≥90% coverage

Connection with the final project (Module 8)

The final project requires ≥90% coverage for the whole application. What you learn here — the iterative coverage workflow — is exactly what you'll replicate at a larger scale. If you master the measure→generate→measure cycle here, the final project is the same process repeated.


Boundaries: What This Module Will NOT Do

  • ❌ Mocking — Covered in Module 6. Here we work with code that's directly testable
  • ❌ Mutation testing with tools — We mention the concept but don't use mutmut/cosmic-ray
  • ❌ Coverage as a CI/CD metric — The focus is learning to use coverage, not integrating it into pipelines
  • ❌ Performance profiling — Coverage measures test execution, not performance

Evidence of Success

By the end of this module, you'll know you succeeded if:

  • ✅ You can run pytest --cov and read the resulting report
  • ✅ You can explain what "85% line coverage, 72% branch coverage" means
  • ✅ You can use Claude Code to generate tests that cover specific gaps
  • ✅ You can list at least 8 categories of edge cases
  • ✅ You completed the project: a module with ≥90% coverage

Summary

  • ✅ Coverage is the map: it shows which code runs during the tests
  • ✅ Edge cases are the territory: the scenarios that cause real bugs
  • ✅ Claude Code amplifies your ability to discover edge cases
  • ✅ The workflow is iterative: measure → identify → generate → measure again
  • ✅ Property-based testing with hypothesis complements the prompts
  • ✅ The ≥90% coverage target is reached with strategy, not brute force

Next capsule: pytest-cov and coverage reports — the tool to measure your test suite.


Additional Resources

  1. pytest-cov Documentation - Official pytest-cov documentation
  2. Coverage.py - The underlying measurement tool
  3. Hypothesis Documentation - Property-based testing for Python
  4. Martin Fowler: Test Coverage - A perspective on coverage
  5. OWASP Testing Guide - Edge cases in security

Module 5 — Testing with Claude Code Guide Discovering the tests you didn't write