liveBook · Manning

Code coverage

As explained in Learn Go with Pocket-Sized Projects

Code coverage is the percentage or proportion of program code executed by a test suite.

Code coverage measures the percentage of program code executed by a test suite. In Go, run `go test -cover` to expose untested branches or paths and check whether tests cover the intended functionality. section 8.3.2

Use coverage while building and reviewing tests:

  • Run `go test ./... -cover` after adding tests. section 6.2.6
  • Cover error cases, such as rejecting an amount whose precision exceeds its currency’s precision. section 6.2.6
  • Review coverage after finalizing a library or adapter, then look for missed branches and edge cases. section 8.3.2 section 6.3.2

Testing validation and API conversion

Tests can exercise `NewAmount` with both valid input and an excessive-precision error, or verify that an API adapter converts a `session.Game` into the expected response shape. Coverage helps reveal paths that these tests do not execute. section 8.3.2 section 6.2.6

> go test ./... -cover

Run the supplied Go command to measure coverage across packages. section 6.2.6

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines coverage as executed code proportion and applies it through commands, but does not detail measurement internals.
Examples
Demonstrates `go test -cover`, `NewAmount` error coverage, and API response conversion tests.
What it assumes
Assumes familiarity with test suites and Go tests while treating coverage measurement as a practical testing step.
What you can do after
Diagnose/debug with it by finding unexecuted branches and paths in Go tests.
How it connects
Connects coverage with testing, error cases, branches, paths, edge cases, and API adapters.

Also explained in

Compare how 14 books explain code coverage →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.