Developers should test until the marginal defect prevented costs more than the test that catches it—not until coverage hits an arbitrary number. The practical floor for most production software is automated checks on every critical path plus a regression test for every bug that escaped, scaled up or down by the blast radius of failure. Testing is an investment with diminishing returns, so the right amount depends on what breaks, who feels it, and how fast you can fix it. That's the whole answer in miniature. The rest of this piece is about applying it without drowning in either bugs or test suites.

Why "test everything" and "test nothing" both fail

Testing has a cost curve and a value curve, and they cross somewhere. Every test you write consumes time now and time forever after—it runs in CI, it breaks when code changes and needs repair, and it can produce false confidence if it's asserting trivialities. The value of a test is the expected cost of the bug it would have caught, discounted by the probability it actually catches it. That sounds abstract, so make it concrete.

Suppose a payments team ships a rounding bug that overcharges 0.4% of transactions by a cent. At 200,000 transactions a day and 1.5 cents average overcharge, that's about $12 a day in refunds—annoying but trivial. Now suppose a currency-conversion bug mischarges by $4 on 2% of international orders at 20,000 orders a day: that's $1,600 a day, plus chargebacks, plus support tickets, plus trust damage. Same "payments" domain, wildly different testing investment justified. The comparison is not "payments code needs high coverage." It's "this specific code path with this specific failure mode needs a test."

The failure mode on the other side is equally real. When teams mandate a coverage number, engineers learn to satisfy the number. They write getter tests, snapshot tests of config objects, and assertions that can never fail. You get 90% coverage and a suite that takes twenty minutes and doesn't catch the null-pointer bug that shipped to production. Coverage measures which lines executed, not which behaviors were verified. It's a useful diagnostic—low coverage on a critical module usually means untested behavior—but a terrible target.

The risk-based rule: score each area before choosing a depth

The most defensible allocation method I know is a simple three-factor score per module or feature. Rate each factor 1 to 5:

Impact if it fails: data loss or money at 5; cosmetic at 1. Likelihood of defects: complex logic, frequent change, and tricky dependencies raise it; stable, boring code lowers it. Detectability elsewhere: if a human or monitoring catches the failure within minutes, the need for pre-release tests drops; if a silent wrong answer ships and reconciles at month-end, it rises.

Multiply the three. A 4×4×5 = 80 module (money movement, complex, silent failure) justifies exhaustive automated tests, property-based testing on the arithmetic, and multiple integration paths. A 1×2×1 = 2 module (a static help-text page) justifies essentially nothing beyond the fact that it builds. Most of your codebase lives in the middle, around 20–40, where the answer is unit tests on the logic and one end-to-end check of the wiring.

That scoring session takes an hour per team per quarter and is worth more than any coverage mandate. It tells you where the next test dollar goes first, and it gives you language to defend not testing something when a stakeholder asks why the marketing page has no test suite.

The spending-split that works for most teams

For a typical web application with a CI pipeline, a workable default is to aim for roughly 70% of your test volume at the unit level, 20% at integration, and 10% at end-to-end—not because of the percentages themselves but because of what each level buys.

Unit tests are cheap to write, fast to run, and pinpoint failures. They're ideal for business rules: tax calculation, discount eligibility, state-machine transitions, parsing. They're weak at catching wiring bugs—the wrong function called, the database column named wrong, the serialization mismatch.

Integration tests catch exactly that, and they're where surprise bugs concentrate in modern applications. A test that hits a real (or faithfully containerized) database through the actual data-access layer catches schema drift, query errors, and transaction-boundary bugs that unit tests with mocked repositories cannot. These are the tests that earn their runtime cost.

End-to-end tests through the UI are the most expensive to write and maintain—they're flaky, slow, and break on irrelevant visual changes. Keep them for the critical user journeys only: sign-up, login, checkout, whatever the core conversion is. A suite of ten of these run on every pull request beats two hundred browser tests that everyone learns to ignore.

The shape matters more than the ratio. If your unit tests mock everything and your E2E tests cover nothing real, you've inverted the value. Ask what each layer can't catch, and put a test at the layer that can.

Coverage, in context

Line coverage is the easiest number to gather and the easiest to misread. Here's what a coverage report actually tells you: these lines ran during the suite. It doesn't tell you what was asserted, whether the assertion was meaningful, or whether the test would fail if the code broke. Mutation testing—deliberately breaking the code and checking whether tests fail—is the honest measure of test strength, but it's slow enough that most teams run it on critical modules only, not the whole repo.

A sane position: treat coverage as a smoke alarm, not a goal. If a module handling money or authentication shows 40% line coverage, that's a signal to investigate, not necessarily a mandate to reach 90%. If a stable utility module shows 40%, it might be fine. Some teams set differential coverage—new and changed lines must be covered—which avoids the retroactive grind on legacy code while keeping new code from adding to the untested pile.

Branch coverage is stricter than line coverage and worth preferring when your tooling supports it, because it catches the untested else path. But neither metric replaces thinking about which inputs matter.

What "enough" looks like on the ground

Here's a practical checklist for deciding you're done with testing on a given change:

1: Every bug you've fixed has a regression test. This is the single highest-yield rule in the business. A bug escaped, so the risk was real; the test locks it out. 2: The risky paths from your risk score have tests at the level where the bug would manifest. Arithmetic at unit level, persistence and wiring at integration level, the golden path at E2E. 3: Edge and boundary inputs are covered where the logic is conditional. Empty collections, zero, negatives, max values, nulls, unicode, time zones, leap days, concurrent access. These are where defects cluster. 4: Error handling paths have at least one test each. People write happy-path tests and skip the retry, timeout, and malformed-response branches, which are exactly the branches that run in production at 3 a.m. 5: You can state what you did not test and why. If the answer is "I ran out of time," that's a known risk you can flag; if the answer is "that path is unreachable by construction," that's fine. An honest gap inventory is more valuable than a padded coverage number.

That checklist is the operational version of "enough." It scales: a tiny script gets items 1 and 3; a payment service gets all five plus mutation testing on the money math.

Tests that hurt more than they help

Not all tests pay for themselves. A few categories that routinely cost more than they return:

Tests of trivial code. Repository methods that just delegate to an ORM, DTOs with only getters, configuration parsing with no logic. These tests can't fail in interesting ways, so they add maintenance surface for zero protection.

Over-mocked tests. If a test mocks five collaborators and asserts on a call count, it's testing your mocking library. It breaks when you refactor the implementation, even though behavior is unchanged. That's negative value—it actively penalizes improvement.

UI tests asserting pixel positions or exact copy. They break on design changes that are working correctly, and teams respond by deleting them or disabling them. Assert on behavior and structure, not appearance.

Snapshot tests of large objects. A 3,000-line snapshot nobody reviews gets "updated" with a single command whenever it fails, which means it never catches anything. Snapshots work for small, intentional structures.

Tests written after the deadline to hit a metric. The tell is a suite that grows by 200 tests and catches zero bugs for months. More tests is not progress.

The maintenance cost deserves emphasis because it's the part teams underbudget. A test suite is a second codebase. Every test that exists will one day need reading, repairing, or retiring. When you write a test, you're committing to that. It's usually worth it—but only when the test protects something.

When to spend more: failures that justify heavy testing

Some conditions reliably justify going far beyond the default. Raise the testing budget sharply when:

Failure is silent and costly. Financial calculations, tax logic, billing, data migrations, access-control decisions. The telescope here is that a bug may go unnoticed until damage compounds—month-end reconciliation, a security audit, a customer's spreadsheet. Property-based testing shines for arithmetic invariants: for any inputs, totals must equal the sum of parts, refunds can't exceed charges, and conversions round-trip within tolerance. The cost of a fix post-release dwarfs the cost of the test. A firmware update that bricks devices, a schema change that needs a backfill, a mobile app release that takes a week to propagate. Pre-release testing is cheap compared to deployment. Regulation or audit requires evidence. In healthcare, finance, and some safety contexts, you may need demonstrable test records, not just tests. That's a compliance requirement, not a quality judgment, and it changes the calculus. Many people depend on the interface. Shared libraries, APIs, and internal platforms break downstream systems you can't see. Contract tests and backward-compatibility tests earn their keep here.

In those zones, the honest answer to "how much testing" is "more than feels economical, because the tail risk is that bad." That's not gold-plating; it's matching spend to exposure.

When to spend less: context that lowers the bill

Conversely, pull back when:

Feedback is fast and cheap. A feature behind a flag with weekly releases and instant rollback doesn't need the same pre-release coverage as a monthly shipped artifact. Monitoring and fast recovery substitute for some pre-release testing—for that specific class of failures, not for logic errors that ship silently. The code is throwaway. Prototypes, spike branches, one-off scripts for a migration you'll run once and delete. Test the migration's result by inspecting it; don't build a test suite for a script. Failure is cosmetic and instantly visible. A broken link on an internal tool, a typo in a developer-only debug page. A human notices it in a minute. The logic is trivially inspectable. A pure function that's five lines and depends only on its parameters has radically less risk than an equivalent amount of imperative code with branches and external state.

Note the pattern: the discount comes from fast, cheap detection and recovery, not from "we're in a hurry." A tight deadline is a reason to prioritize tests by risk score, not to skip the high-risk ones. The classic failure is cutting the payment test to make the date—and shipping a rounding error.

A worked allocation for a realistic feature

Take an e-commerce discount engine: percentage-off codes, fixed-amount codes, stacking rules, expiry dates, and a minimum-purchase threshold. Rate it: impact 4 (wrong totals, customer trust), likelihood 4 (branchy rules, frequent change), detectability 3 (customers notice overcharging, but subtle undercharging may not) → score 48, firmly in "test thoroughly."

What that looks like in practice:

Unit tests (the bulk): each rule in isolation, stacking order, expiry boundaries (one second before and after), threshold exactly at the boundary, zero and negative inputs, currency rounding at half-cent values. Call it 40–60 focused tests. This is the cheap, high-yield core. Property-based checks (a handful of properties, hundreds of generated cases): final price never exceeds undiscounted price, discounts never stack past a configured ceiling, and the order of applying independent codes doesn't change the total. These catch the combinations you'd never enumerate by hand. Integration tests (maybe 5–10): code validation and redemption end-to-end against a real database, including a concurrent-redemption case where two requests claim a single-use code simultaneously—the classic race you won't find with unit tests. One E2E test: apply a code at checkout and confirm the total on the confirmation page.

Total effort: a day or two of test writing for a component where a silent error could mean thousands of mispriced orders. Meanwhile, the static "shipping policy" page next to it gets zero tests and nobody should lose sleep over it. That asymmetry is the point—it's exactly what a flat coverage target would erase.

Testing in an AI-assisted world

The reference date here is late 2026, and one practical shift is worth naming: AI coding assistants generate plausible code fast, and plausible code is often subtly wrong in exactly the ways tests catch. The asymmetry has grown—generating a candidate solution is now cheap, and verifying it is the bottleneck. That argues for writing the tests from the specification before or alongside the generated implementation, so the tests encode what you meant, not what the code happens to do. Tests generated from the code itself inherit its assumptions and catch far less.

None of that changes the economics above; it just raises the value of a solid test suite relative to the value of hand-written implementation.

The short version

Write a test for every bug you fix. Put real tests on the paths your risk score flags as dangerous, at the layer where a defect would actually appear. Cover the boundaries and error branches. Keep end-to-end tests few and tied to core journeys. Treat coverage as a diagnostic, not a target. Audit your suite occasionally by asking which tests caught a bug in the last year—retire the ones that never could, and invest where the scoring says the exposure is. That's not a number; it's a discipline, and it's the one that keeps both bug counts and maintenance costs down.