liveBook · Manning

Code coverage

As explained in Build High Value Software Systems

A measure of which code elements, such as lines, branches, or functions, are executed during testing.

Code coverage measures which lines, branches, or functions tests execute. A high percentage shows broad traversal, not that tests protect important behavior or catch real defects. section 5.7

Use coverage to spot unexplored paths in high-impact code, then check whether tests assert meaningful outcomes. Treat the percentage as a signal, not a measure of risk protected. section 5.7 section 5.9

Payment service

Tests can execute both successful and invalid-payment paths while missing whether a declined payment leaves inventory untouched. An assertion for that contract may barely change the coverage percentage, yet protect meaningful behavior. section 5.7

Listing 5.11 Additional edge case test added
def test_declined_payment_does_not_reserve_inventory():
    mock_gateway.decline()
    result = service.process(valid_order)
 
    assert result == "failed"
    assert not inventory.is_reserved(valid_order)

This test checks both the failure result and the inventory contract after a declined payment. section 5.7

How Build High Value Software Systems covers it

How deep it goes
Defines line, branch, and function coverage, works through a payment example, and stops short of treating execution as evidence of risk protection.
Examples
Uses payment approval, invalid amounts, declined charges, inventory reservation, and confirmation email to contrast path execution with contract protection.
What you can do after
Evaluate coverage reports to find unexecuted high-impact paths, then inspect whether tests assert meaningful outcomes.
How it connects
Connects coverage to test suites, execution paths, business contracts, and risk-based testing.

Also explained in

Compare how 22 books explain code coverage →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build High Value Software Systems. The section links point to the parts of the book it draws on.