Skip to content

Lesson 2 of 13 · 20m

Testing the Gate: Which Tests Run Where

The PR gate runs fast deterministic tests; the flaky e2e suite and the coverage vanity metrics belong somewhere else.

A pull request gate that runs the full suite dies a predictable death. Week one: the e2e suite takes 18 minutes and flakes twice a day. Week three: developers merge before it finishes. Week six: someone adds "skip e2e" to the merge checklist "temporarily." The gate still exists on paper; it stopped gating anything.

The wrong model is "more tests in the gate equals more safety." Safety lives in the loop being trusted, and trust lives in two properties: the gate is fast enough to wait for, and red always means something. The test pyramid — Google's old 70/20/10 guidance from the GTAC era — is really a latency budget in disguise: lots of unit tests, fewer integration tests, very few end-to-end tests, because each layer costs an order of magnitude more time and flake.

The three tiers and where they run

Unit tests run in the PR gate. They start in seconds, fail deterministically, and point at one file. Lint and typecheck live here too — same latency class.

Integration tests gate merge for the paths that justify them. API contract tests, the database layer against a real Postgres in a service container, auth flows. They cost more — a service container alone is ten to twenty seconds of startup — so they earn their gate slot by covering what unit tests structurally can't: the seams.

End-to-end tests do not gate the PR. They run post-merge on main, on a schedule against staging, or inside the merge queue where latency amortizes across a batch. Putting a browser-driven suite in the PR path is the most common way teams destroy their own gate: e2e flakes from timing, test-data drift, and the browser itself, and every flake costs credibility the gate doesn't earn back.

Flakes: quarantine or fix, never ignore

The discipline is a quarantine list with teeth. A test that fails intermittently moves behind continue-on-error: true with a tracking issue and an expiry — two weeks to fix or delete is a reasonable contract. jest.retryTimes(2) is acceptable for a documented timing-sensitive test, never as a blanket flag. What you can't do is leave flakes green-ish in the main suite; each one teaches that a red build might be nothing, and three months later nobody looks at red at all.

Coverage is a metric, not a gate

Coverage thresholds as merge gates measure the wrong thing — 80% covered code still ships the bug that matters. The useful forms: Codecov's patch status, which requires the diff's new lines to be exercised, and diff-cover, which gates the change rather than the repo's whole history. Mutation testing — Stryker mutating your code and checking whether tests kill the mutants — is the honest measure of suite quality, but it's far too expensive for the gate. Run it periodically on critical modules and feed the survivors back as new tests.

The post-deploy smoke test

The last test isn't in the suite — it runs after deploy: curl -fsS https://api.example.com/healthz plus the one endpoint that screams if the database connection string is wrong. A deploy pipeline without a smoke gate trusts that "the pod started" means "the app works." It doesn't. Kubernetes reports Running for a process crash-looping on a missing env var right up until the readiness probe gives up.

Field notes

  • --maxWorkers=2 for Jest on shared runners — the default worker count oversubscribes CPU and makes the suite slower and flakier.
  • Order the gate cheap-to-expensive: lint in 20s, unit in 2m, integration in 5m. Fail fast, literally.
  • Every test in the gate holds a lease on the team's attention. Audit suite runtime like it's budget.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.