Test pollution

Test pollution image
Test pollution happens when one test leaves behind data or a system state that affects another test. The failure appears unrelated, but the root cause is shared context leaking between tests.

This usually shows up when shared data is not cleaned up, system state is reused unintentionally, or resources remain locked or modified after a test finishes. As test suites grow, these hidden dependencies create failures that are hard to reproduce and even harder to trust.

For example, a user registration test creates abc@xyz.com but doesn’t delete it. Later, another test tries to register the same email and fails with “email already exists.” The second test looks broken, but the real issue is that the first test polluted the system. The failure depends on execution order, which makes it flaky and misleading.

The core problem is not the assertion, it’s isolation. Reliable tests must assume they run alone. That often means rolling back test transactions, generating unique test data, or running tests in disposable environments such as containers that are destroyed after each run.
One way teams uncover test pollution is by running tests in random order or executing individual tests in isolation. If results change based on order, hidden dependencies are already present.
Explore MoT
RiskStorming: Artificial Intelligence image
RiskStorming; Artificial Intelligence is a strategy tool that helps your team to not only identify high value risks, but also set up a plan on how to deal
MoT Software Testing Essentials Certificate image
Boost your career in software testing with the MoT Software Testing Essentials Certificate. Learn essential skills, from basic testing techniques to advanced risk analysis, crafted by industry experts.
Into The Motaverse image
Into the MoTaverse is a podcast by Ministry of Testing, hosted by Rosie Sherry, exploring the people, insights, and systems shaping quality in modern software teams.
Subscribe to our newsletter
We'll keep you up to date on all the testing trends.