Automated Testing (IT)Manual/Automation QA Engineer

How to ensure the stability of automated tests and minimize the number of flaky tests?

Pass interviews with Hintsage AI assistant

Answer.

Stability of automated tests is an important aspect of confident CI/CD and trust in automation.

Background

Initially, automated tests were run manually, and instability did not interfere much. With the growth in the number of tests and integration into pipelines, the emergence of flaky tests (tests that sometimes fail for no apparent reason) has become a significant issue.

Problem

Flaky tests lead to:

  • False alerts and loss of trust in tests
  • Slowing down releases (re-runs)
  • Difficulty in finding real bugs

Solution

What helps:

  • Use "waits" (Explicit/Implicit Waits, sleep — only if no other options are available)
  • Prepare the test environment before the test starts
  • Decompose long/complex automated tests
  • Fix test data, clean up after tests
  • Analyze logs: understand where and why the test is flaky

Example of using waits:

WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "result")) )

Key Features:

  • Analysis of the causes of instability
  • Proper management of test data
  • Use of intelligent waits and correct environment initialization

Trick Questions.

Will mass retry solve the problem of flaky tests?

No, this is just a temporary "patching holes". It does not eliminate the cause — it only masks existing problems.

Can automated tests be run only at night to avoid failures due to load?

Running tests at night will not eliminate instability; it will only reduce the likelihood; the problem remains and must be addressed.

Should all flaky tests be deleted immediately?

No. It is better to try to localize the cause and fix it — only delete if it cannot be stabilized or if it is an outdated, irrelevant test.

Typical Mistakes and Anti-Patterns

  • Using sleep everywhere instead of explicit waits
  • Lack of cleanup procedures (tearDown)
  • Running tests in a "dirty" environment

Example from Life

Negative Case

The team resorted to mass retry of tests that constantly flaked. As a result, the list of "green" tests increased, but the quality of automated tests did not improve — bugs were missed.

Pros:

  • CI/CD often showed a "green" result

Cons:

  • Problems were only found manually, increasing errors in production

Positive Case

The team found and described systematic flaky causes: uncleaned data, UI delays, network failures. They fixed the architecture, added sensible waits, configured the environment — the number of unstable tests sharply decreased.

Pros:

  • Trust in automation
  • Real improvement in release stability

Cons:

  • Time was spent on analyzing and refactoring tests and the environment