読み物Quality Engineering · DevOps

Level: Pro

Production Quality Engineering: Flaky Tests, Release Confidence, and Continuous Improvement

Design a risk-based test strategy, find and fix flaky tests, release with evidence, verify behavior in production, and learn from incidents, with a real flaky test caught by shuffling.

Edeeson Opina9 min read

A Pro lesson card: lesson 15 of the Software Testing & Quality Engineering series, Production Quality Engineering, with the Miso fox cheering.

What you’ll learn

  • Prioritize testing by likelihood and impact
  • Detect, quarantine, and fix flaky tests
  • Release with criteria, feature flags, canaries, and rollback
  • Verify production behavior and learn from incidents
On this page
  1. Before you start
  2. Risk-based test strategy
  3. Flaky tests
  4. A real flaky test
  5. Common causes of flakiness
  6. Handling flaky tests
  7. Release confidence
  8. Verifying behavior in production
  9. Learning from incidents
  10. Measuring and improving
  11. Bringing it together
  12. Common mistakes and troubleshooting
  13. Practical exercise: a quality engineering plan
  14. Key takeaways
  15. References
  16. What's next

A green test suite is a prediction, not a guarantee: it predicts the software will behave well in production. Quality engineering is the practice of making that prediction trustworthy and checking it against reality. This final lesson brings the series together: designing a test strategy around risk, finding and fixing flaky tests (with a real one, caught by shuffling test order), deciding when a release is ready, verifying behavior after it ships, learning from incidents, and improving continuously with a few honest measurements.

Before you start

This lesson builds on the whole series, especially CI quality gates (lesson 10), performance testing (lesson 11), and Security Testing and Software Supply Chain Verification. It helps to have worked on software that's deployed to real users.

Risk-based test strategy

You can't test everything equally (exhaustive testing is impossible, lesson 1), so decide where effort goes. Risk-based testing ranks features by two factors:

  • Likelihood of failure: complex code, frequent changes, new technology, past defects (defects cluster), many integrations.
  • Impact of failure: money, data loss, security, legal exposure, number of users affected, reputational damage.

A simple grid is enough to start:

Text
                   Low impact                     High impact
High likelihood    Test well; automate            Test most: all levels, exploratory, monitoring
Low likelihood     Light checks                   Targeted tests plus production monitoring

For a booking site, checkout and payments land in the top-right corner: unit tests for pricing rules, integration tests for the transaction (lesson 7), E2E tests for the journey (lesson 8), security regression tests (lesson 14), and monitoring in production. A rarely used admin color setting lands bottom-left: a quick check is enough.

Write the strategy down in a short document: what's tested at which level, what's automated, what's explored manually, what runs on each pull request and what nightly, and who owns which suites. Revisit it when the product or its risks change.

Flaky tests

A flaky test passes and fails on the same code. Flaky tests are corrosive: after a few false alarms, people re-run failures without reading them, and real failures get ignored too.

A real flaky test

This suite passes when run normally:

src/flaky.test.tsTypeScript
import { describe, expect, it } from "vitest";

// Shared, mutable state at module level: the root cause.
const cart: string[] = [];

describe("cart", () => {
  it("starts empty", () => {
    expect(cart).toEqual([]);
  });

  it("adds an item", () => {
    cart.push("miso");
    expect(cart).toEqual(["miso"]);
  });
});

It passes in file order, because "starts empty" runs first. But the two tests aren't independent: the second changes state the first depends on. Running in a random order exposes it. Vitest can shuffle tests with a seed, so an order can be reproduced:

Text
default order:          Tests  2 passed (2)
shuffled, seed 1:       Tests  2 passed (2)
shuffled, seed 2:       Tests  2 passed (2)
shuffled, seed 3:       Tests  1 failed | 1 passed (2)
shuffled, seed 4:       Tests  2 passed (2)
Text
     × starts empty 5ms
AssertionError: expected [ 'miso' ] to deeply equal []
- Expected
+ Received
- []
+ [
+   "miso",
+ ]

In a large suite with parallel workers, the order changes between runs without anyone shuffling on purpose, and this becomes the classic "fails sometimes in CI." The fix is isolation: each test gets fresh state, for example with const cart: string[] = [] inside each test, or a beforeEach that resets it.

Common causes of flakiness

  • Shared state: module variables, shared database rows, files, caches.
  • Order dependence: a test relies on another having run first.
  • Timing: fixed sleeps, missing waits in UI tests (lesson 8), race conditions in async code.
  • Time and dates: tests that break at midnight, at month end, or in another time zone.
  • Randomness without a recorded seed.
  • External services and networks: real APIs, DNS, rate limits.
  • Resource limits: tests that pass on a fast laptop and time out on a busy CI runner.

Handling flaky tests

  1. Detect: track tests that fail and then pass on retry. Playwright reports these as "flaky" when retries are enabled; CI dashboards can track rates over time. Running suites shuffled (vitest --sequence.shuffle, PHPUnit --order-by=random) or repeatedly (Playwright --repeat-each) surfaces hidden dependencies.
  2. Quarantine briefly: if a flaky test blocks everyone, move it out of the required suite, with an owner and a deadline, and keep running it separately so you collect data.
  3. Fix the cause: isolation, proper waits, controlled time, fakes for external services.
  4. Never just add retries and forget. Retries are a diagnostic tool and a temporary bandage, not a fix. A flaky test may be revealing a real race condition in the product.

Release confidence

How do you decide a release is ready? Not by a feeling, but by evidence against written release criteria (lesson 10): green suites, no open high-severity defects in scope, performance and accessibility within budgets, security findings triaged. Then reduce the cost of being wrong:

  • Small, frequent releases: smaller changes mean fewer things that can go wrong, and easier diagnosis when something does.
  • Feature flags: ship code turned off, then enable it for staff, then a small group of users, then everyone. Turning a flag off is faster than a rollback.
  • Canary releases: deploy the new version to a small fraction of servers or traffic first, compare its error rates and latency with the current version, and continue only if they're healthy.
  • Automatic rollback: a release process that can return to the previous version in one step, rehearsed before it's needed.

Verifying behavior in production

Testing doesn't end at deployment. Production is where real users, real data, and real scale meet your software:

  • Smoke tests after every deploy (lesson 2): the critical paths work in the real environment.
  • Synthetic monitoring: scripted checks, often reusing E2E tests, that run against production every few minutes and alert when a journey breaks.
  • Real user monitoring: errors and performance from actual users' browsers and devices.
  • Service level objectives (SLOs): targets such as "99.9% of booking requests succeed" and "p95 latency under 400 ms," with alerts when the error budget burns too fast.
  • Error tracking: new exception types after a release are a strong signal of a regression.

Treat production signals as test results, and feed them back: an error that users hit but tests missed points to a missing test.

Learning from incidents

When something goes wrong in production, the goal is to learn, not to blame. A blameless review asks:

  • What happened, and what was the impact?
  • How did we detect it, and how could we have detected it sooner?
  • Why did our tests and checks not catch it? Was there no test, a weak test, a flaky test that was ignored, or an environment difference?
  • What will we change: a new regression test, a better gate, a monitoring alert, a process change?

Then make those changes, and check later that they happened. The most valuable output of an incident is often a new test or gate that prevents the whole class of failure, not just this instance.

Measuring and improving

A few measurements help a team see whether quality is improving. The DORA research program's delivery metrics are widely used because they balance speed and stability:

  • Deployment frequency: how often you release.
  • Lead time for changes: from commit to production.
  • Change failure rate: the share of deployments that cause a failure needing remediation.
  • Failed deployment recovery time: how quickly you recover when one does.

Add quality-specific signals: escaped defects (found in production rather than before), flaky test rate, pipeline duration, and time to fix failing builds. Look at trends, not single numbers, and never turn a metric into a target that rewards gaming it, such as bug counts or coverage percentages (lesson 6).

Bringing it together

A mature quality practice, for a small team or a large one, looks like this:

  • requirements reviewed early, with testable acceptance criteria;
  • tests at the right levels, designed with real techniques, written with the code (lessons 2 to 9);
  • fast, required CI gates, with slower suites scheduled (lesson 10);
  • performance, accessibility, and security tested deliberately, not as an afterthought (lessons 11 to 14);
  • exploratory testing for what automation can't imagine (lesson 5);
  • small releases with flags, canaries, smoke tests, and monitoring;
  • every incident and escaped bug feeding back into tests, gates, and process.

Quality is never finished. It's a loop of predicting, checking, and learning.

Common mistakes and troubleshooting

  • Testing everything equally. Prioritize by risk.
  • Living with flaky tests. Detect, quarantine with an owner, and fix the cause.
  • Retries as a permanent fix. They hide real race conditions.
  • Releasing on gut feeling. Use written criteria and evidence.
  • Big-bang releases. Use flags and canaries to limit the blast radius.
  • No feedback from production. Monitor, and turn escaped defects into tests.
  • Blame after incidents. It hides information; run blameless reviews.
  • A test passes alone but fails in the full suite. Suspect shared state or order dependence; run the suite shuffled with a fixed seed to reproduce.

Practical exercise: a quality engineering plan

For a product you work on:

  1. Draw the risk grid for its ten most important features, and decide the testing depth for each.
  2. Run your test suite shuffled several times (or with repeats). Fix or quarantine, with an owner, any test that fails.
  3. Write release criteria and a rollback procedure, and rehearse the rollback once.
  4. Add one synthetic check that runs a critical journey against production or staging on a schedule.
  5. Take the last production bug or incident and write a short blameless review, ending with one new test or gate.
  6. Record the four DORA metrics for the last month as a baseline.

Key takeaways

  • Prioritize testing by risk: likelihood times impact, written down as a strategy.
  • Flaky tests come from shared state, ordering, timing, time, randomness, and external dependencies; detect, quarantine with an owner, and fix the cause.
  • Release with evidence: criteria, small changes, feature flags, canaries, and a rehearsed rollback.
  • Verify in production with smoke tests, synthetic monitoring, real user data, and SLOs.
  • Learn from incidents without blame, turn escaped defects into tests, and track a few honest metrics over time.

References

What's next

You've finished the Software Testing & Quality Engineering series, from your first test case to quality engineering in production. Testing pairs naturally with version control: if you haven't yet, continue with What Is Version Control? Understanding Git and Repository Hosting, or revisit What Is Software Testing? for the foundations.

See every lesson in Software Testing & Quality Engineering: From Fundamentals to Production-Ready Software