/qa-mobile:espresso-suitefrom qa-mobile
Writes and runs Android UI tests using Google's Espresso framework: onView matchers, perform actions, check assertions, IdlingResource synchronization, and ./gradlew connectedAndroidTest execution.
Ships in qa-mobile. 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.
Per espresso-doc:
"Espresso is a framework for writing concise, beautiful, and reliable Android UI tests."
The canonical example:
@Test
fun greeterSaysHello() {
onView(withId(R.id.name_field)).perform(typeText("Steve"))
onView(withId(R.id.greet_button)).perform(click())
onView(withText("Hello Steve!")).check(matches(isDisplayed()))
}
The shape: onView(<matcher>).perform(<action>).check(<matches>).
The framework auto-waits via "synchronization conditions" per espresso-doc:
"Each time a test invokes onView(), Espresso waits to perform the corresponding UI action or assertion until these synchronization conditions are met:
- The message queue doesn't have any messages that Espresso needs to immediately process
- There are no instances of AsyncTask currently executing a task
- All developer-defined idling resources are idle"
This eliminates the need for Thread.sleep for stock Android
async work.
// app/build.gradle
android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.6.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.6.1'
androidTestImplementation 'androidx.test:rules:1.6.1'
}
Per espresso-doc, Espresso ships as multiple packages:
| Package | Purpose |
|---|---|
espresso-core | Core View matchers, actions, assertions. |
espresso-web | WebView support. |
espresso-idling-resource | Synchronization for background jobs. |
espresso-contrib | DatePicker, RecyclerView, Drawer actions, accessibility checks. |
espresso-intents | Intent validation + stubbing. |
espresso-remote | Multi-process functionality. |
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
@RunWith(AndroidJUnit4::class)
class CheckoutTest {
@get:Rule
val activityRule = ActivityScenarioRule(MainActivity::class.java)
@Test
fun applyPromoCode() {
onView(withId(R.id.promo_field)).perform(typeText("WELCOME10"), closeSoftKeyboard())
onView(withId(R.id.apply_button)).perform(click())
onView(withId(R.id.subtotal)).check(matches(withText("$22.49")))
}
}
When the app uses something Espresso doesn't auto-track (e.g. custom thread pool, RxJava chains), wire an IdlingResource:
class NetworkIdlingResource : IdlingResource {
@Volatile private var callback: IdlingResource.ResourceCallback? = null
@Volatile private var pendingRequests = 0
override fun getName() = "NetworkIdlingResource"
override fun isIdleNow() = pendingRequests == 0
override fun registerIdleTransitionCallback(cb: IdlingResource.ResourceCallback) {
callback = cb
}
fun increment() = synchronized(this) { pendingRequests++ }
fun decrement() = synchronized(this) {
pendingRequests--
if (pendingRequests == 0) callback?.onTransitionToIdle()
}
}
// Wire from production code at network call sites:
networkIdlingResource.increment()
api.fetchOrders().enqueue { _, _ -> networkIdlingResource.decrement() }
// Register in test setup:
@Before fun setup() { IdlingRegistry.getInstance().register(networkIdlingResource) }
@After fun teardown() { IdlingRegistry.getInstance().unregister(networkIdlingResource) }
Without IdlingResource, Espresso assumes idle when its built-in trackers report idle - async work the framework can't see triggers flake.
// Matchers
withId(R.id.button) // by ID
withText("Submit") // by displayed text
withContentDescription("Login") // by content description
hasSibling(withText("Email")) // structural relationship
isDisplayed() // currently visible
// Actions
click(), longClick()
typeText("..."), clearText()
scrollTo(), swipeLeft(), swipeUp()
pressBack()
// Assertions
matches(withText("Hello"))
matches(isDisplayed())
matches(isEnabled())
doesNotExist()
// espresso-contrib provides RecyclerViewActions
onView(withId(R.id.cart_list))
.perform(RecyclerViewActions.actionOnItemAtPosition<MyViewHolder>(0, click()))
onView(withId(R.id.cart_list))
.perform(RecyclerViewActions.scrollTo<MyViewHolder>(hasDescendant(withText("BOOK-001"))))
A test that taps "Take photo", "Pick file" or "Choose contact" leaves the app under test: on CI the real camera or picker opens, Espresso cannot drive it, the test fails, and the foreign activity can stay on top for the next test. Espresso-Intents records outgoing intents and answers them with a canned result (espresso-intents):
// app/build.gradle.kts
androidTestImplementation("androidx.test.espresso:espresso-intents:3.6.1")
@RunWith(AndroidJUnit4::class)
class AttachDocumentTest {
@get:Rule val scenario = ActivityScenarioRule(ComposeMessageActivity::class.java)
@Before fun setUp() = Intents.init() // start recording before any action
@After fun tearDown() = Intents.release() // always, or the next test inherits stubs
@Test fun attachingAPdfShowsItsName() {
val picked = Intent().setData(Uri.parse("content://test/docs/invoice.pdf"))
intending(hasAction(Intent.ACTION_OPEN_DOCUMENT))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, picked)) // 1. stub first
onView(withId(R.id.attach)).perform(click()) // 2. then act
intended(allOf(hasAction(Intent.ACTION_OPEN_DOCUMENT), hasType("application/pdf"))) // 3. verify
onView(withId(R.id.attachment_name)).check(matches(withText("invoice.pdf")))
}
}
IntentsTestRule
"initializes Espresso-Intents before each test annotated with @Test
and releases Espresso-Intents after each test run"
(espresso-intents); with ActivityScenario, do the same
with Intents.init() / Intents.release() in @Before / @After.data Intent or a missing extra, an empty
ActivityResult makes the test pass through the wrong branch. For
MediaStore.ACTION_IMAGE_CAPTURE without EXTRA_OUTPUT, the camera
app returns "a small Bitmap in the extras, under the key "data""
(photo-basics), so the stub must put one there.intended(), which works like Mockito.verify()
(espresso-intents), so the test proves the right intent
was sent rather than only that the UI changed.@get:Rule val perms: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.CAMERA)
(grant-permission).Thread.sleep to wait for the result: the stubbed result is
delivered on the main thread and Espresso synchronizes on it.# Unit + UI tests on connected device / emulator
./gradlew connectedAndroidTest
# With test orchestrator (each test in fresh process - preferred for isolation):
android {
defaultConfig {
testInstrumentationRunnerArguments clearPackageData: 'true'
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
}
jobs:
ui-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
script: ./gradlew connectedAndroidTest
- uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: app/build/outputs/androidTest-results
The test results land in JUnit XML at
app/build/outputs/androidTest-results/.../TEST-*.xml -
consumable by junit-xml-analysis (in the qa-test-reporting plugin).
| Anti-pattern | Why it fails | Fix |
|---|---|---|
Thread.sleep for async waits | Espresso has built-in sync; sleeps mask race conditions. | Use IdlingResource for unsupported async (Step 3). |
withText("Submit") for buttons | Translation breaks the test. | withId(R.id.submit_button) or withContentDescription. |
Missing closeSoftKeyboard() after typing | Keyboard obscures next view; click() misses. | Chain closeSoftKeyboard() after typeText. |
Skipping IdlingResource for Retrofit / OkHttp | Network async invisible; flaky. | Wire IdlingResource (Step 3) OR use OkHttp's IdlingResource bridge. |
| Tapping a button that opens the camera, a picker or another app | Leaves the app; CI has no way to drive the foreign activity. | Espresso-Intents intending(...).respondWith(...) before the tap; intended(...) after. |
Intents.init() without Intents.release() | Recorded intents and stubs leak into the next test. | Release in @After (or use the rule). |
| One mega-test that asserts 10 things | One failure obscures others; debugging hard. | One assertion target per @Test. |
| Skipping test orchestrator | Tests share process; one test's state leaks. | Enable ANDROIDX_TEST_ORCHESTRATOR (Step 6). |
appium-testing.-core, -web, -contrib, -idling-resource,
-intents, -remote).intending, verification with intended.ACTION_IMAGE_CAPTURE thumbnail in the "data" extra.GrantPermissionRule.xcuitest-suite - iOS sibling.appium-testing - cross-platform
alternative.junit-xml-analysis - downstream parser.evals/clicks-land-on-the-keyboard-in-checkout/criteria.json (opens in a new tab)evals/clicks-land-on-the-keyboard-in-checkout/task.md (opens in a new tab)evals/espresso-compose-hybrid/criteria.json (opens in a new tab)evals/espresso-compose-hybrid/task.md (opens in a new tab)evals/espresso-intents-camera/criteria.json (opens in a new tab)evals/espresso-intents-camera/task.md (opens in a new tab)evals/espresso-recycler/criteria.json (opens in a new tab)evals/espresso-recycler/task.md (opens in a new tab)evals/german-lane-red-while-the-english-one-is-green/criteria.json (opens in a new tab)evals/german-lane-red-while-the-english-one-is-green/task.md (opens in a new tab)evals/nightly-run-red-but-every-test-passes-alone/criteria.json (opens in a new tab)evals/nightly-run-red-but-every-test-passes-alone/task.md (opens in a new tab)evals/orders-tests-hang-after-the-asynctask-rewrite/criteria.json (opens in a new tab)evals/orders-tests-hang-after-the-asynctask-rewrite/task.md (opens in a new tab)evals/product-wants-coverage-that-follows-the-user-out-of-the-app/criteria.json (opens in a new tab)evals/product-wants-coverage-that-follows-the-user-out-of-the-app/task.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
android-testing, ui-testing, espresso, instrumentation-tests
8 skills in this plugin
/appium-testingUse for any question or task about Appium mobile UI tests, even a quick fix, including tests that break after an Appium upgrade and suites that pass on Android but fail on iOS: one suite for iOS and Android (native or React Native) with XCUITest, UiAutomator2 and Espresso drivers, capabilities, clients in JS, Python, Java, Ruby or .NET, simulators, emulators and device farms./detox-testingUse whenever a React Native app needs end-to-end tests with Detox: gray-box runs inside the app, by.id, by.text and by.label matchers, waitFor for extra sync, and the Jest runner. Flutter is flutter-testing; cross-platform black-box is appium-testing; YAML flows are maestro-flows./flutter-testingUse whenever a Flutter app needs tests: unit tests with flutter test, widget tests with testWidgets and WidgetTester, integration_test on simulators, emulators or devices, choosing the layer per change, mockito with build_runner, LCOV coverage and CI./maestro-flowsUse for any question or task about Maestro, even writing one short flow, or a mobile UI test format that product managers and other non-engineers can read and edit: .maestro/*.yaml with tapOn, inputText, assertVisible and swipe, for iOS, Android, Flutter, React Native and web, with nested flows and JavaScript hooks./mobile-a11y-test-authorUse when an iOS or Android app needs accessibility tests: XCUITest performAccessibilityAudit (iOS 17+), VoiceOver labels and traits, Espresso AccessibilityChecks, Accessibility Scanner and TalkBack order, plus WCAG checks for labels, 44pt and 48dp touch targets, contrast and focus order./mobile-device-matrix-toolkitUse when deciding which iOS and Android devices and OS versions to test on at each stage to control CI cost: smoke per PR, regression per merge, full farm at release. Generates Appium configs per device from one YAML, runs a GitHub Actions matrix and merges JUnit results into one table.npx claudepluginhub testland/qa --plugin qa-mobileOther plugins' skills for the same job