Test coverage

Definition
Test coverage is the share of your code that runs during automated tests, a rough guide to how much of the product is checked whenever something changes.

Why it matters

With good coverage on the parts that matter, a change that breaks something is more likely to turn a check red before a customer sees it. With none, every release is shipped on trust. That matters more when an AI coding agent is writing the code, because it can change many files at once and cannot be relied on to notice what it broke.

A perfect percentage is a trap of its own. Teams that chase it write tests to lift the figure, not to catch failures.

How to apply it

  • Decide first where a failure would hurt most: payments, sign-in, permissions, data deletion, the core workflow. Cover those paths before anything else.
  • Write tests that assert a specific correct value, not tests that only confirm the code did not crash.
  • Add a test the moment a bug is fixed, so the same fault cannot return unseen.
  • Watch the trend rather than a single figure, and read gaps as a map of where you are exposed.
  • Run the tests automatically on every change through CI/CD, so nobody has to remember.

What it is

An automated test is a small program that runs part of your product and checks the result. Test coverage is a report that says how much of the code was actually run while the tests ran. If a product has 1,000 lines and the tests run 700 of them, line coverage is 70 per cent. Some tools also measure branches, which count whether both sides of each if-then decision were exercised.

The number tells you what was run. It does not tell you what was checked. A test that runs a function and never looks at its answer counts as coverage but protects nothing.

Worked example

Suppose a twelve-person software firm has an invoicing tool with about 4,000 lines of code and test coverage of 40 per cent. The payment and permission code is among the parts nobody tests. The team sets up GitHub so that its automated tests run on every change, and writes tests for payments and user roles first. Each test asserts an exact result, such as the correct VAT total on a sample invoice. Coverage rises to 72 per cent over three months.

The number matters less than the trend. In the first month the build turns red twice: once for a rounding error on credit notes, and once for a permission check that let a junior user see another client's invoices. Both were caught before a customer saw them.

Tools in the example

Some links are affiliate links: we may earn a commission at no cost to you. It never decides a ranking. How we work with partners

  1. Article

    Regression

    The kind of failure coverage is meant to catch early.

  2. Article

    Code review

    A second check that coverage cannot replace.

  3. Article

    Staging environment

    Where a tested change gets a final realistic look.

  4. Article

    Agent evals

    The same discipline applied to an AI agent's output.

Where it shows up

  • Writing copy that feels like conversation instead of marketing. How to sound like yourself.
    12 chapters