You inherited a codebase with almost no tests, and the usual advice says to add coverage before changing anything. I would not make that the default in 2026. Over the last two years, generating tests has become easier than checking whether their assertions are true. Your first job is to establish where expected behavior comes from, then spend the test budget where a wrong change can escape.
Generated tests make an independent oracle more valuable than another test case
AI assistants can now draft fixtures, mocks, and assertions faster than a QA engineer can review their assumptions. That changes the economics of the old “write a test for every function before touching it” rule: the scarce resource is no longer test code, but evidence that the expected result is correct. A generated test that copies the current implementation’s output may faithfully preserve the defect you were asked to fix.
I disagree with Inherited an untested codebase What QA advice is obsolete now where broad advice about obsolete practices risks treating every untested module as the same problem. For a calculation with a published rule, use the rule as the oracle. For an undocumented export consumed by another team, use a recorded consumer expectation. For behavior that nobody can explain, label a characterization test as a record of current behavior, not a declaration that the behavior is right.
Ask an assistant to propose cases, but require a source beside each expected value: an OpenAPI 3.1 contract, a product decision, a production example checked by an owner, or an independently calculated result. If the only source is the function under test, leave the assertion out until you can investigate it. That rule costs review time, but it prevents fluent-looking tests from turning accidental behavior into a permanent requirement.
As a starting limit to tune for your team, spend 90 minutes establishing an oracle for a risky change before writing a large suite. In that period, inspect the call site, find a real input, identify its downstream consumer, and ask who would notice an incorrect result. If you cannot establish an oracle, report that gap in the change review and test a narrower property you can defend, such as “the export remains parseable” rather than “every exported value is correct.”
I would not ask an AI assistant to generate hundreds of assertions from a snapshot of the existing output, because volume would make an unverified assumption look authoritative. The useful change since 2024 is not that an assistant can write tests; it is that you can afford to reject cheap tests and spend your attention on their provenance.
Repository-wide coverage gates are the wrong first constraint
A percentage gate sounds objective, but it directs work toward lines that are easy to execute rather than behavior that matters. In an inherited codebase, a new test can raise coverage.py’s reported percentage while never checking a result. Conversely, an integration test that verifies a consequential database write may cover relatively few lines. Coverage is useful as a map of what ran; it is not evidence that the assertions were sound.
Pin the tooling so the map is reproducible. For a Python repository, pytest 8.3 and coverage.py 7.6 are concrete versions to evaluate against the project’s Python version; do not silently upgrade the runner while establishing a baseline, because collection or plugin changes can alter the apparent result. The following commands run an existing characterization-test directory and print the first uncovered lines in each file under src/. They assume those packages are installed and the directory exists.
python -m coverage erase
python -m coverage run -m pytest -q tests/characterization
python -m coverage json -o .coverage.json
python - <<'PY'
import json
data = json.load(open(".coverage.json"))
for path, file in data["files"].items():
if path.startswith("src/") and file["missing_lines"]:
print(path, "missing:", file["missing_lines"][:10])
PY
Use that output alongside git diff, not as a demand to cover every listed line. Ask whether the changed path has a test that would fail for the specific mistake you fear. For a price calculation, deliberately change a boundary value on a branch and check that the test fails. For a file writer, remove a required field and check that a consumer-facing test fails. This is a small, manual fault-injection check; it gives a reviewer more information than a green percentage alone.
Before setting a CI threshold, establish what CI itself does. Repeat the same commit for 30 runs as an initial sample size to adjust, and record failures by test and environment. If a particular test fails three times in those runs, its observed failure rate is 10%; that arithmetic is an example of what to measure, not a claim about your repository. Fix or isolate the cause before using that test as a release signal, because an unreliable alarm teaches people to ignore real failures.
I would not impose a repository-wide coverage target on the first inherited-code change, because it rewards unrelated test additions and makes the threshold look like assurance. Require instead that the change review name its risk, its oracle, and a test or manual check that could expose the feared failure.
Consumer contracts often beat golden-master snapshots
Golden-master tests record a large current output and compare future output against it. They still win when the output is stable, the entire artifact is the product, and a person can review a meaningful diff—for example, a small generated document with agreed formatting. Their cost is review noise when timestamps, ordering, or incidental fields change. A snapshot approval made to clear CI can then conceal a real regression among harmless differences.
Consumer contract tests win when only part of an output matters to a caller. An OpenAPI 3.1 schema can specify an HTTP response shape; Pact can verify expectations held by a known consumer. Their cost is coordination: someone must identify the consumers, decide which expectations are promises, and keep verification running against the provider. The explicit comparison is therefore golden-master snapshot versus consumer contract: choose the snapshot when the complete stable artifact deserves review; choose the contract when compatibility at a boundary matters more than incidental output. Neither option establishes that an undocumented business rule is correct.
This distinction matters more now because generated snapshots are exceptionally easy to produce. Test Inherited Code Cheaply Without Faking Assurance makes a useful case for modest spending, but cheap recording is the wrong bargain if nobody can say which recorded fields a consumer relies on. A smaller contract can cost more to agree on and less to maintain, because it excludes irrelevant churn.
For an inherited HTTP service, start with one consequential exchange rather than a full schema inferred from traffic. Capture a request that a real consumer makes, remove secrets, and confirm which response fields it reads. Run that expectation against the service in CI. If PostgreSQL behavior affects the response, a PostgreSQL 16 instance launched with Testcontainers can exercise real transactions; a hand-written mock cannot reveal a database constraint that the mock never implemented. Use a mock when the dependency’s behavior is already specified and the test is about your code’s response to it.
Set an initial review allowance of 20 minutes per changed snapshot as a value to revisit. If reviewers cannot determine within that time whether the diff is safe, shrink the snapshot or replace it with explicit assertions. The point is not to make every review fast; it is to stop treating an unreadable approval as a passed test.
A release check should expose uncertainty rather than hide it
Older advice often put the entire burden on a pre-merge test suite: keep adding tests until the team feels safe to ship. That is a poor default for an untested system, because some important behavior depends on production configuration, data, or traffic that a fresh CI environment does not reproduce. Pre-merge checks still catch mistakes; they should not be asked to certify conditions they never exercise.
Separate the claims you can verify. A pytest test may establish that a transformation handles known boundary inputs. A Playwright 1.50 browser test may establish that a user can complete a critical path against a deployed candidate. Neither proves that a production integration will accept tomorrow’s payload. For that boundary, record the expected protocol response and add a post-deployment check that can fail visibly without modifying customer data.
OpenTelemetry traces can connect a request to a failing dependency call, while Prometheus counters can show whether failures increase after release. Instrument the same operation your pre-merge test exercises, or the two signals will be hard to compare. A rollout alert should name an observable failure, such as rejected requests for that operation, rather than an unexplained change in a broad service metric. This costs instrumentation and on-call attention, but it gives the team a way to detect a mistake that escaped the inherited suite.
Keep the evidence in GitHub Actions or the project’s equivalent CI record: the tested commit, tool versions, test result, and any known gap. GitHub’s documented default job timeout is 360 minutes; that vendor-published ceiling is a safeguard against an endless job, not a sensible testing budget. Set a shorter job timeout based on the feedback your team can actually use, because a result arriving after reviewers have moved on is less likely to shape the change.
Do not silently quarantine a failing test merely to restore a green badge. If it is flaky, record its repeat rate and owner; if it tests an uncertain requirement, record the missing oracle. A visible exception is uncomfortable, but it lets the next engineer distinguish “not tested” from “tested and passed.”
Your next test should start with a failure you can name
Pick the next change waiting for review and write down one plausible harmful failure before opening the test directory. Find an independent source for the expected behavior, then add the smallest check that would detect that failure. If no source exists, say so in the review and seek one from the consumer or owner. That first decision will do more for your inherited codebase than an impressive new test count.


