Skip to content
Back to skills

Android Testing

ASecurity

`Thread.sleep` waits for an arbitrary amount of wall-clock time. It makes the suite slower, can still be too short on a busy emulator or CI worker, blocks the test thread, and does not prove that the repository, coroutine, worker, or UI has reached the state being asserted. That creates timing-dependent flaky tests and hides real synchronization problems. Wait for an observable condition with a bounded timeout. For Compose: ```kotlin composeRule.onNodeWithTag("load_button").performClick() com...

  • 584 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 5, 2026
developmentkotlinnodeapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 18 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Android Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Android Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-android-testing-ee1260e7/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-testing-ee1260e7)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Why `Thread.sleep(2000)` is bad in a UI test

`Thread.sleep` waits for an arbitrary amount of wall-clock time. It makes the suite slower, can still be too short on a busy emulator or CI worker, blocks the test thread, and does not prove that the repository, coroutine, worker, or UI has reached the state being asserted. That creates timing-dependent flaky tests and hides real synchronization problems.

Wait for an observable condition with a bounded timeout. For Compose:

```kotlin
composeRule.onNodeWithTag("load_button").performClick()

composeRule.waitUntil(timeoutMillis = 5_000) {
    composeRule.onAllNodesWithTag("result")
        .fetchSemanticsNodes()
        .isNotEmpty()
}

composeRule.onNodeWithTag("result").assertIsDisplayed()
```

Use a stable text, content description, or test tag representing the user-visible completion state. `awaitIdle()` or `waitForIdle()` is appropriate for Compose work already scheduled through Compose, but it is not a general wait for arbitrary network or background-thread work.

For Espresso, expose the asynchronous operation with an `IdlingResource`, commonly a `CountingIdlingResource`, and register/unregister it with `IdlingRegistry` in setup and teardown:

```kotlin
idlingResource.increment()
repository.loadAsync(
    onComplete = {
        try {
            // Update the UI.
        } finally {
            idlingResource.decrement()
        }
    },
)
```

For coroutine unit tests, use `runTest` with the skill’s `MainDispatcherRule`, then call `advanceUntilIdle()` (or `advanceTimeBy(...)` for a deliberate virtual delay). For WorkManager, use its test APIs and controlled executors. Do not replace synchronization with a longer sleep; make the async work observable and fail after a finite timeout with a useful diagnostic. Tests should assert loading, success, and error states rather than implementation timing.


Files in this skill

  • eval-1.baseline.md2.7 KB
  • eval-1.with-skill.md2.4 KB
  • eval-2.baseline.md2.8 KB
  • eval-2.with-skill.md2.5 KB
  • eval-3.baseline.md2.2 KB
  • eval-3.with-skill.md1.8 KB
  • trigger-1.md137 B
  • trigger-10.md139 B
  • trigger-11.md143 B
  • trigger-2.md143 B
  • trigger-3.md139 B
  • trigger-4.md150 B
  • trigger-5.md143 B
  • trigger-6.md146 B
  • trigger-7.md127 B
  • trigger-8.md152 B
  • trigger-9.md142 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.