Counting the Cost and the Benefit of a Library Test Suite

Tests for a library are cheaper than tests for an application in one way, because the inputs and outputs are well defined, and more valuable in another, because a regression ships to every dependent at once. Still, a suite has running costs: CI minutes, flaky failures to chase and tests to update when internals change. This page offers a way to think about whether the next chunk of testing effort is worth it.

A per-release model

cost_per_release    = ci_minutes × minute_value + flaky_triage_hours + test_maintenance_hours
benefit_per_release = Σ over regressions caught (p_regression × cost_if_shipped)
cost_if_shipped     = maintainer_fix_hours + Σ dependents_hit × their_hours_lost

The key term is cost_if_shipped. For an application, a regression costs you. For a library, it also costs each dependent who installs the bad version, investigates, pins, and later unpins. That multiplier is why library tests often earn their keep at a smaller probability of catching something.

Illustrative example

Hypothetical Package D adds tests that exercise its public API against the packed tarball on the oldest and newest supported runtimes. All figures are assumptions.

ItemAssumed value
Extra maintainer time per release on these tests0.5 hours
Chance per release that they catch a regression1 in 10
Maintainer hours to fix a shipped regression3
Dependents who would install the bad version before a fix20
Hours lost per affected dependent1

Cost if shipped is 3 + 20 × 1 = 23 hours. Expected benefit per release is 0.1 × 23 = 2.3 hours against a cost of 0.5 hours. Even if you only count your own time, the expected benefit is 0.3 hours, close to break-even. Counting dependents makes the case clear.

Where tests pay most for a package

Where they pay least

Tests that assert internal implementation details cost the most to maintain and catch little that users would notice, because internals are free to change in any release. Duplicate coverage across many runtime-and-OS combinations adds CI minutes faster than it adds signal; the CI matrix math page shows how fast those multiply. Flaky tests are the worst case, since they cost triage time and teach contributors to ignore red builds.

For the practical side, see testing the tarball before publishing, the package test matrix Q&A and the case study of a breaking change that shipped in a patch release.