/quality-skills:espressofrom quality-skills
Designs, implements, debugs, and stabilizes Espresso tests for native Android UI automation, including IdlingResource sync, ViewMatchers, and instrumented test setup.
Ships in quality-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in Espresso — Google's native Android UI testing framework. Your goal is to help engineers write fast, reliable Espresso tests, manage async work via IdlingResources, and integrate the instrumented tests with the Android build. Don't fabricate Espresso method names, ViewMatcher / ViewAction names, or AndroidX Test artifact names. When uncertain, point the reader to developer.android.com/training/testing and the AndroidX Test docs.
Check .agents/qa-context.md (fallback: .claude/qa-context.md) before answering. Pay attention to:
androidx.test.ext.junit.runners.AndroidJUnit4 and ActivityScenario.IdlingResource for stable tests.If the file does not exist, ask: Java or Kotlin, what async libraries the app uses, target device strategy, and whether the app has been instrumented for setHasTransientState / IdlingResource cooperation.
sleep().When not to use Espresso:
app/build.gradle.kts (or .gradle):
dependencies {
androidTestImplementation("androidx.test.ext:junit:<pinned-version>")
androidTestImplementation("androidx.test.espresso:espresso-core:<pinned-version>")
androidTestImplementation("androidx.test:runner:<pinned-version>")
androidTestImplementation("androidx.test:rules:<pinned-version>")
}
android {
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
}
Verify exact artifact versions against developer.android.com/jetpack/androidx/releases/test.
Tests live under src/androidTest/ (instrumented) — distinct from src/test/ (JVM unit tests, see jest-vitest / junit-testng analogues).
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class LoginScreenTest {
@get:Rule
val activityScenarioRule = ActivityScenarioRule(LoginActivity::class.java)
@Test
fun signs_in_with_valid_credentials() {
onView(withId(R.id.email)).perform(typeText("[email protected]"), closeSoftKeyboard())
onView(withId(R.id.password)).perform(typeText("Pa\$\$w0rd-fake"), closeSoftKeyboard())
onView(withId(R.id.sign_in)).perform(click())
onView(withId(R.id.welcome)).check(matches(isDisplayed()))
}
}
Three building blocks:
onView(matcher) — locate a view..perform(action, ...) — drive an action (click, type, scroll)..check(assertion) — assert on the view.| Matcher | Use |
|---|---|
withId(R.id.x) | Stable ID. First choice. |
withText("...") / withText(R.string.x) | Visible text. |
withContentDescription("...") | Accessibility text. |
withTagValue(...) | View tag. |
withParent(...) / hasDescendant(...) | Compose matchers for hierarchy. |
isDisplayed() / isEnabled() / isChecked() | State predicates. |
allOf(m1, m2) / anyOf(...) | Combine matchers. |
Strongly prefer withId(...) — IDs are deliberate, stable, and survive refactors better than text or tag.
| Action | Use |
|---|---|
click() / doubleClick() / longClick() | Touch events. |
typeText("...") / replaceText("...") | Text input. replaceText is faster than clearText().typeText(...). |
closeSoftKeyboard() | Dismiss keyboard. |
scrollTo() | Scroll the target into view. |
swipeLeft() / swipeRight() / swipeUp() / swipeDown() | Swipes. |
pressBack() | System back. |
Custom via ViewAction interface | When built-ins don't fit. |
RecyclerViewActions (from androidx.test.espresso:espresso-contrib) provides matchers and actions for RecyclerView items:
onView(withId(R.id.product_list))
.perform(RecyclerViewActions.actionOnItemAtPosition<MyViewHolder>(3, click()))
onView(withId(R.id.product_list))
.perform(RecyclerViewActions.scrollTo<MyViewHolder>(hasDescendant(withText("Widget"))))
Espresso waits for the main thread to be idle. But async work (background fetches, RxJava, Coroutines) is invisible to that check. You'll get flaky tests where Espresso races past async work.
IdlingResource is the bridge — it tells Espresso "still working."
class HttpIdlingResource(private val httpClient: MyHttpClient) : IdlingResource {
private var callback: IdlingResource.ResourceCallback? = null
override fun getName(): String = "HttpIdlingResource"
override fun isIdleNow(): Boolean {
val idle = httpClient.inFlightCount() == 0
if (idle) callback?.onTransitionToIdle()
return idle
}
override fun registerIdleTransitionCallback(cb: IdlingResource.ResourceCallback) { callback = cb }
}
Register and unregister around tests:
@Before fun before() { IdlingRegistry.getInstance().register(httpIdlingResource) }
@After fun after() { IdlingRegistry.getInstance().unregister(httpIdlingResource) }
For modern apps using Coroutines, CountingIdlingResource is a simple counter; libraries like okhttp-idling-resource wrap OkHttp. Avoid sleep — IdlingResource is the right primitive.
ActivityScenario launches and controls an activity in tests; FragmentScenario (from androidx.fragment:fragment-testing) does the same for fragments.
val scenario = ActivityScenario.launch(LoginActivity::class.java)
scenario.onActivity { activity ->
// call methods on the actual activity instance
}
scenario.moveToState(Lifecycle.State.STARTED)
scenario.close()
These give you direct access to the activity/fragment under test — useful for state-setup that bypasses the UI.
Espresso-Intents (androidx.test.espresso:espresso-intents) stubs and verifies startActivity calls:
@get:Rule val intentsRule = IntentsRule()
@Test fun opens_browser_on_help_click() {
Intents.intending(hasAction(Intent.ACTION_VIEW)).respondWith(
Instrumentation.ActivityResult(Activity.RESULT_OK, null)
)
onView(withId(R.id.help)).perform(click())
intended(allOf(hasAction(Intent.ACTION_VIEW), hasData("https://support.example.com")))
}
Useful for tests that would otherwise launch external apps (browser, camera, mail).
| Command | Purpose |
|---|---|
./gradlew connectedAndroidTest | Run all instrumented tests against a connected device/emulator. |
./gradlew :app:connectedDebugAndroidTest | Specific build variant. |
./gradlew connectedAndroidTest -PandroidTestInstrumentationRunnerArguments.class=com.example.LoginScreenTest | One test class. |
For CI:
reactivecircus/android-emulator-runner (or equivalents) for emulator-on-CI.gcloud firebase test android run ...).Thread.sleep instead of IdlingResource — flake forever.withText for buttons that get localized — breaks the moment translations land. Use withId or withText(R.string.x).adb shell settings put global window_animation_scale 0 (also transition_animation_scale, animator_duration_scale).connectedAndroidTest — unit tests belong in src/test/, run via ./gradlew test. Mixing them slows the instrumented suite.closeSoftKeyboard() after typeText — subsequent clicks land on the keyboard, not the target view.androidx.test:orchestrator runs each test in its own process; without it, leaked state cascades.When helping with Espresso, ask:
androidx.test:orchestrator) in use?espresso-contrib?What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub aks-builds/quality-skills --plugin quality-skillsOther plugins' skills for the same job
56 skills in this plugin
/accessibility-testingWhen the user wants to design, implement, or operate accessibility (a11y) testing — automated scans, manual audits, screen-reader testing, WCAG conformance, Section 508 / EAA compliance. Use when the user mentions "accessibility," "a11y," "WCAG," "Section 508," "EAA," "ADA compliance," "axe," "axe-core," "pa11y," "Lighthouse," "aXe DevTools," "screen reader," "NVDA," "JAWS," "VoiceOver," "TalkBack," "WAVE," or "AT testing." For visual diff see visual-regression. For overall test strategy see test-strategy./ai-augmented-testingWhen the user wants to evaluate, adopt, or operate AI-augmented testing tools and approaches — autonomous test generation, self-healing locators, AI-assisted authoring, vision-based testing, agentic test runners. Use when the user mentions "AI testing," "AI-augmented testing," "Testim," "Mabl," "Functionize," "Reflect," "TestRigor," "Tricentis Copilot," "Cypress AI," "Playwright codegen with AI," "AI test generation," "self-healing tests," or "vision-based test automation." For LLM-product evals see llm-eval-testing. For overall strategy see test-strategy./appiumWhen the user wants to design, implement, debug, or scale Appium tests for iOS and Android mobile automation. Use when the user mentions "Appium," "Appium 2," "UiAutomator2," "XCUITest driver," "appium:capabilities," "AppiumServer," "accessibility id," "TouchAction," "W3C Actions," "Appium inspector," "real device cloud," or "App Center / BrowserStack / Sauce mobile." For Android-native frameworks see espresso. For iOS-native see xcuitest. For React Native specifically see detox. For YAML-driven mobile flows see maestro. For desktop web automation see selenium / playwright / webdriverio.