liveBook · Manning

Branch coverage

Branch coverage is a test coverage metric measuring the proportion of a program’s control-flow branches executed by tests.

How 3 Manning books explain it

Unit Testing Principles, Practices, and Patterns

Branch coverage is a test coverage measure indicating which conditional branches in code are executed by tests.

How it is used
Uses executed conditional paths to assess test-suite completeness while warning against treating coverage as a quality score.
How deep it goes
Defines the ratio, demonstrates two paths, and explains limits involving assertions, external libraries, and imposed thresholds.
Examples
Uses an IsStringLong method, a short-string test, a two-path graph, and a 50% branch-coverage result.
What you can do after
Evaluate test-suite completeness, investigate low coverage, and balance coverage benefits against maintenance costs.

Read how Unit Testing Principles, Practices, and Patterns explains branch coverage →

100 Java Mistakes and How to Avoid Them

Branch coverage is the fraction of control-flow branches exercised by a test suite.

How it is used
Uses test reports to reveal unexercised control-flow alternatives that line or instruction coverage can conceal.
How deep it goes
Explains missing branches through an infinite-loop example and testing guidance, but stops short of coverage-tool configuration.
Examples
Uses a hasPercentD loop with inputs such as "%%%%" and "%%d%%%d" to illustrate branch-sensitive tests.
What you can do after
Diagnose/debug with it by locating untested loop branches and adding tests for zero, single, and repeated iterations.

Read how 100 Java Mistakes and How to Avoid Them explains branch coverage →

Practices of the Python Pro

Branch coverage is a test coverage metric measuring which branches of a program's control flow have been executed by tests.

How it is used
Guides tests toward exercising alternative execution paths and exposing overlooked edge cases.
How deep it goes
Defines execution-path coverage and its limitation, then points to tooling without developing measurement internals.
Examples
Uses a Python function with type checking, a loop, a length condition, an early return, and a fallback return.
What you can do after
Apply it via the Coverage package to inspect branch coverage metrics for tests.

Read how Practices of the Python Pro explains branch coverage →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.