liveBook · Manning

Unit test

As explained in Build High Value Software Systems

An automated test that verifies the behavior of a small isolated unit of software.

A unit test checks behavior at the smallest unit of change. It can define correct behavior before implementation, constrain design, and catch defects before they spread. section 5.2 section 5.9

Use unit tests where quick feedback protects meaningful behavior:

  • Test business rules, calculations, transformations, and invariants; these are suited to unit-level checks. section 5.3
  • Prefer tests that run quickly, remain stable through refactoring, and define correctness rather than police internal calls. section 5.2
  • Choose the test layer by risk: unit tests suit high-impact business calculations, while boundary and customer-journey risks may need other layers. section 5.3
Listing 5.2 A typical TDD test
def test_shipping_cost_for_domestic_package_under_5kg():
    assert calculate_shipping(weight=3, destination="domestic") == 5.99

A test-first example specifies the expected shipping cost for a domestic package under five kilograms. section 5.2

Treat the test as a control, not a coverage target: protect behavior where early detection prevents rework, and avoid accumulating slow or untrusted checks. section 5.2 section 5.9

How Build High Value Software Systems covers it

How deep it goes
Defines speed, stability, and behavioral focus, and places unit tests within risk-based test layers.
Examples
Uses a shipping-cost calculation and business-rule testing to illustrate unit-level checks.
What you can do after
Apply test-first checks to specify business behavior and select unit tests for suitable risks.
How it connects
Connects unit testing to test-driven development, integration testing, and end-to-end testing.

Also explained in

Compare how 18 books explain unit test →

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.