Which Tests Should You Run After a Code Change?

Kyle · · 17 min read
Code testing workflow showing what tests to run after code change

What tests to run after a code change is rarely answered by rerunning whatever CI throws at you. In a multi-module repo, one shared helper can reach an API, worker, and CLI.

Start with behavior and reachability: changed control flow, callers, entry points, contracts, and data boundaries. Don’t let an AI assistant pick tests from the diff alone.

Before you hit merge:

  • Run tests that execute the changed path
  • Add boundary tests for affected APIs, queues, or storage
  • Keep required release gates intact

Know what you proved.

Why This Question Gets Expensive Fast

You change one file. CI lights up like you touched the payment system, auth layer, and half the monorepo. That feeling is familiar because most build systems are conservative by design, and conservative gets expensive fast.

If a file sits inside a module, many pipelines respond by running that module’s tests, the tests of dependent modules, and then the tests of whatever depends on those. Adyen described this exact problem in 2024: a tiny change can trigger thousands of tests that never get near the edited line. Safe, yes. Efficient, not really.

The waste is not just CPU time.

  • Engineers wait longer for signal
  • CI capacity gets burned on low-value work
  • Reviewers get slower feedback
  • Old failures and flaky tests start to drown out the change you actually made

In larger teams, the problem gets uglier. Testing evidence ends up spread across branches, pull requests, environments, and builds. Some of it is still useful. Some of it expired the moment the next merge landed. That ambiguity is where people start guessing.

And guessing creates the usual bad loop: run everything to feel safe, or run too little and spend the next few hours wondering what you missed.

Our position is simple: the goal is not to run fewer tests at any cost. The goal is to run the right tests first, get fast signal on the real blast radius, and still respect the broader suites your release policy requires.

Good test selection is about order and confidence, not bravado.

What Counts as Impacted After a Change

When people ask what tests to run after code change, they often mean "what touched this file?" That’s too small. Impacted code is not the edited file. It’s every reachable behavior that can change because of that edit.

That usually spans a few layers:

  • Direct logic inside the changed module
  • Callers that depend on that logic
  • Entry points that can reach it, like endpoints, jobs, CLI commands, event handlers, or scheduled tasks
  • Data boundaries, such as database writes, queues, caches, and file storage
  • Config, templates, resource files, and environment variable usage
  • Cross-repo consumers if the code is shared outside the current repo

This is where teams get tripped up on tests for impacted code. Structural reachability and proven test coverage are not the same thing.

Reachability tells you what can be affected. Coverage tells you what a selected test actually executed. You need both if you want affected test selection to be more than a hopeful guess.

A shared validation helper is a good example. Structurally, it may be reachable from one public API, one worker, and one admin command. That gives you your change based test scope. Coverage then tells you whether your chosen API and worker tests really executed the changed paths, or only brushed past them.

Dead code changes this math too. Unreachable code should not get the same testing weight as active paths. But deletion still needs care if that code had hidden consumers, stale scripts, or cross-repo references nobody documented. "Looks unused" is not a proof.

Start With the Kind of Change, Not With the Test Suite

Before you pick tests, classify the change. This is where calm starts. Not every edit deserves the same regression checks for edits, and treating them all the same is how teams either panic or waste a day.

Here’s a practical matrix.

Change typeMinimum test scopeWhy it may need to widen
Local refactor, no intended behavior changeNearby unit tests, direct module integration testsControl flow, async behavior, or error handling changed
Shared helper or utility changeHelper unit tests plus all direct consumer testsFan-out into multiple services or user flows
Public API contract changeAPI tests, contract checks, consumer-facing integration testsExternal clients, SDKs, or versioned contracts
DB query, schema, or migration changeIntegration tests with real persistence, migration checksBackfill scripts, reporting paths, rollback concerns
UI-only copy or style changeComponent tests, narrow smoke pathHidden logic in rendering, analytics, feature flags
Config or env var changeStartup checks, affected integration tests, deploy smokeRuntime-only failures, missing defaults, environment drift
Auth, validation, or security-sensitive changeUnit, integration, API, negative-path testsAccess control bugs hide in edge cases
Performance hot path changeFocused perf checks plus normal functional testsFunctional pass can still ship a slow system
Dead code deletionReachability check, build, narrow regression around former callersHidden downstream consumers or dynamic loading

One distinction matters more than it gets credit for: targeted testing after refactor is not the same as "I only renamed things."

A rename or file move is usually lower risk. A refactor that changes branching, retries, serialization, timing, or exception handling is not low risk just because the intent was "no behavior change." Intent doesn't execute in production. Code does.

Map the Blast Radius With Callers, Entry Points, and Affected Modules

This is the structural center of the whole exercise. If you skip it, the rest is theater.

We use a repeatable blast-radius workflow:

Before choosing tests

  1. Changed files

    List the changed files

  2. Direct callers

    Find direct callers

  3. Transitive callers

    Find transitive callers if the code is shared

  4. Reachable entry points

    Identify entry points that can reach those callers

  5. Affected modules

    Group the affected modules or services

  6. External contracts

    Note external contracts: API responses, emitted events, DB writes, files

Tiny diffs often hide large risk. A two-line helper change used by checkout, refunds, and reporting is not a two-line change. File size tells you almost nothing about business exposure.

A good review here includes non-code edges:

  • Config files that switch behavior
  • Templates that shape responses
  • Environment variables that gate execution paths
  • Resource files that coverage tools often ignore
  • Cross-repo packages or services that consume the changed code

For larger repositories, this is where structure-aware tooling helps. Pharaoh maps repositories into a knowledge graph so teams and MCP clients can inspect dependencies, callers, endpoints, environment variable usage, blast radius, and dead code before picking a test scope. In multi-module or multi-repo systems, that matters because the risky part is often not where the edit happened, but where the edit can be reached.

Use a short verification pass before you trust your map:

  • Is the changed code actually reachable?
  • Which entry points can hit it?
  • Is the module shared or isolated?
  • Did the edit cross service or repo boundaries?
  • Did any contract shape change on the way out?

If you can’t answer those, you’re not selecting tests yet. You’re still guessing.

Map of what tests to run after code change across callers, entry points, and affected modules

Pick Tests by Confidence Layer, Not by Habit

Different tests answer different questions. That sounds obvious, but teams still fall into the habit of treating test names as categories instead of purposes.

Think in confidence layers.

Unit tests are fast and local. They tell you whether the small piece still behaves in isolation.

Integration tests tell you whether your code still works with the real things it depends on, usually storage, files, queues, or other local infrastructure. This is where query bugs, type mismatches, and serialization problems show up.

API and contract tests tell you whether request and response behavior still matches what callers expect.

End-to-end tests tell you whether a real journey still works across the whole stack. They also fail for annoying reasons. Use them for value, not comfort.

Smoke tests ask a simple question: is the system alive enough that deeper checks are worth running?

Regression tests are different. They are not a layer. They are a promise that a specific bug stays dead.

A sane default looks like this:

  • Run unit tests frequently, often on every commit
  • Add integration and API tests when changes cross boundaries or touch persistence, formatting, contracts, or runtime wiring
  • Use end-to-end tests for high-value flows and higher-risk merges
  • Run smoke checks after deploys and on critical paths
  • Add a regression test after every bug fix

Performance-sensitive changes deserve their own note. Some teams run small focused performance checks on every commit or PR for a few hot paths instead of waiting for release. Netflix described a version of this for TV UI performance work. That’s the right instinct. Functional green does not mean user experience is fine.

Build a Focused Regression-Test Plan for the Change in Front of You

A useful plan is short. It’s a written argument, not a ceremony.

Every focused plan should answer five questions:

Turn impact into coverage

  1. Change

    What changed?

  2. Affected scope

    What can now be affected?

  3. Fast tests

    Which fast tests should run now?

  4. Slower tests

    Which slower tests should run before merge or release?

  5. Always-run suites

    Which broader suites still run no matter what?

A simple format works well:

  • Changed files
  • Affected callers and entry points
  • Affected modules or services
  • Chosen tests with reasons
  • Known blind spots
  • Required broader gates

Illustrative example: shared validation helper refactor

Changed files:

  • validation/shared_rules.py

Affected:

  • Public orders API
  • Background invoice worker
  • Admin import CLI

Immediate tests:

  • Helper unit tests
  • Integration tests in the orders module
  • API contract tests for the orders endpoint

Broader checks:

  • Worker-path integration check
  • Admin flow smoke test
  • Required release suite if this is customer-facing

Blind spots:

  • Indirect consumers in another repo
  • Error formatting differences not covered by current unit tests

Illustrative example: copy-only UI change

Changed files:

  • CheckoutSummary.tsx
  • locale strings

Likely scope:

  • Component tests or snapshot checks
  • One narrow smoke path through checkout summary

Probably not needed:

  • Full backend suite, unless the UI text change also altered conditional rendering or event wiring

The point is not to be fancy. The point is to make the reasoning visible so another engineer can challenge it.

Validate the Plan Before You Trust It

A planned scope is only useful if the selected tests can actually be found, executed, and interpreted.

Do a reality check:

  • Are test labels or markers accurate?
  • Do the selected tests still exist?
  • Are any silently skipped?
  • Where coverage data exists, do those tests hit the changed files or classes?
  • Is your mapping fresh, or are you relying on stale data from weeks ago?

Fine-grained coverage is far better than module-level guesswork. Mature setups track which tests cover which files or classes. Better ones also connect resource files and config-driven behavior, because plain code coverage often misses those edges.

A good pattern is to refresh selection data with full post-merge runs or scheduled broad runs. Adyen described this clearly: PR-time selection uses stored coverage data, and full-suite runs after merge keep the map from drifting away from reality. That’s a practical model.

One guardrail needs to be stated without wiggle room:

Graph reachability does not prove test coverage.

Reachable code can still be untested. And reachable code is never, by itself, a reason to skip mandated suites.

There’s another problem in large teams that people understate: old testing evidence ages badly. Results from another branch, another environment, or another build may still be useful, or may be irrelevant after a merge. If a code path changed, retest it. Don’t hide behind stale green.

When Simple Dependency Rules Work and When You Need More

There are three common ways teams choose change based test scope.

1. Transitive dependency selection

This is the easiest place to start because build metadata already exists. It’s usually safe in the narrow sense that it catches anything depending on the changed files. The downside is noise. In large repos, this can select ten thousand tests for one change. Meta described this problem in its predictive test selection work.

2. Fine-grained static and dynamic analysis

This combines structure with actual test coverage. It narrows tests for impacted code much better than module-level rules alone and gives you a risk view, not just a giant list. If you care about callers, entry points, blast radius, and dead code, this is where things start to feel controlled.

3. Predictive selection

This uses historical failures and test outcomes to estimate which tests are worth running. It can cut test cost hard when the data is good. But it needs historical depth, care around flaky tests, and clear recall targets so the team knows what risk it is accepting.

The scale of the trade-off is measurable. In a production deployment at Facebook, a predictive test-selection strategy cut total testing infrastructure cost by half while still reporting more than 95% of individual test failures and more than 99.9% of faulty changes to developers. That is a useful benchmark for setting expectations: a selective system should be judged not only by tests skipped, but also by its measured failure and faulty-change recall. The study also accounted for nondeterministic, or flaky, test outcomes.

Our recommendation ladder is blunt:

  • Start with dependency-based selection if you have nothing else
  • Add coverage and impact analysis as soon as possible
  • Consider predictive methods only after your structural mapping and coverage data are trustworthy

Safety-critical and regulated systems often choose safer selection strategies and rerun more. That’s not laziness. It’s an explicit risk decision.

Common Mistakes in Targeted Testing After Refactor

Precision is not the danger. False confidence is.

Here are the mistakes we see most often:

  • Treating refactors as risk-free because behavior was "supposed" to stay the same
  • Ignoring indirect callers of shared helpers and internal libraries
  • Missing data shape changes, serialization changes, retries, or error-path edits that unit tests won’t catch
  • Forgetting config files, feature flags, templates, and environment variables
  • Trusting stale coverage maps or stale ownership metadata
  • Deleting "dead" code without proving reachability and downstream references
  • Letting an AI assistant propose a test list from the diff alone
  • Using targeted testing as an excuse to bypass required security, compliance, or release suites

A diff is not architecture. That sentence saves people a lot of trouble.

What This Looks Like in an AI-Assisted Workflow

If you’re using Claude Code, Cursor, Codex, or another MCP client on a large repo, the workflow should be structured. AI is good at assembling a first-pass plan. It is bad at inventing missing architecture and then sounding confident about it.

A practical playbook looks like this:

  • Give the assistant the diff
  • Give it architecture context
  • Ask for direct callers, transitive callers, entry points, affected modules, and contract edges
  • Ask for a first-pass test plan by layer
  • Ask it to list blind spots and required suites that still must run

Useful prompt directions, in plain English:

  • Identify changed behaviors, direct callers, transitive callers, entry points, and likely affected modules
  • Propose the smallest safe pre-merge test set, then a broader release-confidence set
  • Challenge the plan by listing what could still regress even if all selected tests pass

This is where structural context matters. On larger repositories, Pharaoh can give MCP clients the graph they usually lack, and PR Guard can surface pull-request signals like regression risk, test coverage gaps, unreachable exports, and breaking changes. Helpful, yes. Final authority, no.

You still need source reads, test discovery checks, and your required release gates.

AI-assisted workflow showing what tests to run after code change

What a Healthy CI Policy Looks Like

One-off judgment is useful. A repeatable team policy is better.

A sane cadence usually looks like this:

  • On every commit: fast unit checks and tiny local smoke checks that matter
  • On every pull request: targeted integration and API tests for affected areas
  • Post-merge: broader runs that refresh coverage data and catch drift
  • Before release: wider regression, end-to-end, security, and performance gates as required
  • After every bug fix: add a regression test that fails first, then stays in the suite

This lowers mean time to repair because defects found before merge are cheaper than defects found after release. Strong testing confidence comes from earlier signals, not from one exhausting late-stage test marathon.

The policy should also be observable.

Developers should know why a test ran. Reviewers should know why a test was skipped. And when a miss happens, the team should revisit the selection rule instead of blaming "bad luck." Bad luck is often just unexamined scope.

Conclusion

Testing after a code change is not a ritual of rerunning everything just in case. It’s a judgment call grounded in actual architecture, real dependencies, real entry points, and honest limits.

Start with the change type. Map callers, entry points, affected modules, and contract edges. Pick tests by the kind of confidence you need. Then validate the plan with coverage, discovery checks, and the broader suites your process still requires.

Here’s the immediate next step: on your next PR, write a six-line impacted-test plan before you rerun the suite. Then check whether your reasoning came from the system’s actual graph or from habit. That small pause changes more than people expect.

Article Record

ReferencesPrimary sources used for this article
  1. What to test and your approach
  2. SWE-191 - Software Regression Testing - SW Engineering Handbook Ver D - Global Site
  3. Test selection at Adyen saves time and resources - Adyen
  4. Google SRE - Stress Testing: Build Confidence in System
  5. Fixing Performance Regressions Before they Happen
  6. Focusing Test Efforts While Servicing Large Systems
  7. CRANE: Failure Prediction, Change Analysis and Test Prioritization in
  8. Addressing the Regression Test Problem with Change Impact Analysis for Ada
Update HistoryMeaningful revisions to this article
Initial publication.
← Back to blog