Find the Polluting Test Behind an Order-Dependent Test Failure
Last updated: November 29, 2026
Quick Overview
A formatting test passes when run alone but fails in the full suite because an earlier test leaves global state behind. Explain the root cause class, write a tool that finds the polluting test with few suite runs, and describe how to fix both tests.
0
0
0 solved
A formatting test passes when run alone but fails in the full suite because an earlier test leaves global state behind. Explain the root cause class, write a tool that finds the polluting test with few suite runs, and describe how to fix both tests.
Google's continuous integration runs tests sharded and in varying orders, so order-dependent tests show up as mysterious failures. The onsite interviewer checks whether the candidate recognizes shared mutable state as the cause, uses a bisection strategy rather than trying every pair, and proposes a real fix instead of pinning test order.
What the Interviewer Expects
- Names shared global state (singletons, env vars, locale, caches) as the cause
- Confirms the victim passes alone before searching
- Bisects the preceding tests to find a polluter in O(log n) runs
- Fixes the polluter with proper teardown or dependency injection
- Hardens the victim to set the state it relies on
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- What if two tests together are needed to pollute the state?
- How would you detect order dependence proactively in CI?
- How does test sharding across machines change the symptoms?
- What if the victim fails only when run after a test in another shard?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- Input: the list of tests and the victim name; running a suite returns per-test pass or fail.
- Output: the single test whose earlier execution makes the victim fail, or None if the failure is not or...
High-Level Design
First run the victim alone. If it fails alone it is simply broken. Then run all other tests followed by the victim to confirm order dependence. Now bisect: run the first half of candidates then the vi...