flaky-test-stabilizer

Diagnose and stabilize flaky Android tests across coroutines, clocks, idling, and Compose.

Updated Jan 2, 2024
One-click install
npx skills add https://github.com/Mithrandir21/game-deals-app --skill flaky-test-stabilizer-mithrandir21
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: flaky-test-stabilizer
Source: https://github.com/Mithrandir21/game-deals-app/tree/main/.claude/skills/flaky-test-stabilizer
Command: npx skills add https://github.com/Mithrandir21/game-deals-app --skill flaky-test-stabilizer-mithrandir21

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Flaky tests that pass locally but fail in CI erode trust in the test suite and slow down development. This Skill provides a structured diagnostic process to reproduce intermittent failures, classify their root cause, apply the correct fix, and verify the fix with repeated runs. ## Core Features & Use Cases - Systematic flake reproduction: Run tests 50–200 times in loops to measure failure rates before and after fixes. - Root-cause classification: Match failures to categories like coroutine dispatcher misuse, time/clock dependencies, missing IdlingResources, network non-determinism, shared state, Robolectric mismatches, and Compose mainClock issues. - Fix verification and prevention: Prove fixes with repeated runs and add CI guards, lint rules, and review practices to prevent regressions. - Use Case: A ViewModel test fails 10% of the time in CI. The Skill identifies a missing test dispatcher, swaps in UnconfinedTestDispatcher with Dispatchers.setMain, and confirms 0 failures over 200 reruns. ## Quick Start Ask the assistant to diagnose why my instrumented test passes locally but fails intermittently in CI and suggest a fix.

Frequently Asked Questions about flaky-test-stabilizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix a flaky Android test that passes locally but fails in CI?▼

First reproduce the flake by running the test 50–200 times in a loop, then capture the failing assertion, logs, and thread dumps. Match the failure to a category such as dispatcher misuse, clock dependency, or environment differences between local and CI emulators.

How to fix coroutine races in ViewModel unit tests?▼

Inject a CoroutineDispatcher instead of using Dispatchers.Main or Dispatchers.IO directly. In tests, call Dispatchers.setMain with UnconfinedTestDispatcher or StandardTestDispatcher, use runTest instead of runBlocking, and assert Flow values with Turbine.

Should I use Robolectric or instrumented tests for flaky behavior?▼

Robolectric shadows some Android APIs imperfectly, so tests can pass on the JVM but fail on device. Move framework-heavy tests to instrumented runs and keep pure logic as JVM unit tests where behavior is deterministic.

Why does my Compose test fail even after waitForIdle returns?▼

waitForIdle can return while animations are still mid-flight or text has just appeared. Use waitUntil with a timeout, or disable autoAdvance on composeTestRule.mainClock and advance time explicitly with advanceTimeBy.

Is adding retries or Thread.sleep a valid fix for flaky tests?▼

No. Retries and Thread.sleep hide the underlying race and slow the suite without fixing it. Reserve @Retry for truly external systems, and fix synchronization with IdlingResource, test schedulers, or proper awaiting instead.