An overview on how Espresso works for Android instrumentation testing, also there is an overview of Application Exerciser Monkey, a utility tool from the Android SDK.
by devs familiar with the Android app codebase - Lets you interact with your Android app just like any user would do - Runs on emulators or physical devices
text & close the soft keyboard .perform(typeText(TEXT_TO_BE_TYPED), closeSoftKeyboard()) // Find the button, then click on it onView(withId(R.id.buttonChangeText))
text & close the soft keyboard .perform(typeText(TEXT_TO_BE_TYPED), closeSoftKeyboard()) // Find the button, then click on it onView(withId(R.id.buttonChangeText)) .perform(click())
text & close the soft keyboard .perform(typeText(TEXT_TO_BE_TYPED), closeSoftKeyboard()) // Find the button, then click on it onView(withId(R.id.buttonChangeText)) .perform(click()) // Find the TextView with the message
text & close the soft keyboard .perform(typeText(TEXT_TO_BE_TYPED), closeSoftKeyboard()) // Find the button, then click on it onView(withId(R.id.buttonChangeText)) .perform(click()) // Find the TextView with the message onView(withId(R.id.textViewMessage))
text & close the soft keyboard .perform(typeText(TEXT_TO_BE_TYPED), closeSoftKeyboard()) // Find the button, then click on it onView(withId(R.id.buttonChangeText)) .perform(click()) // Find the TextView with the message, then check text was changed onView(withId(R.id.textViewMessage))
text & close the soft keyboard .perform(typeText(TEXT_TO_BE_TYPED), closeSoftKeyboard()) // Find the button, then click on it onView(withId(R.id.buttonChangeText)) .perform(click()) // Find the TextView with the message, then check text was changed onView(withId(R.id.textViewMessage)) .check(matches(withText(TEXT_TO_BE_TYPED)))
// ... perform an action indicating the item position .perform( RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>( 30, // the position of the item in the RecyclerView click() ) )
RecyclerView onView(withId(R.id.myRecyclerView)) // ... perform an action indicating the item position .perform( RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>( hasDescendant(withText(containsString("Your order total is"))), click() ) )
RecyclerView onView(withId(R.id.myRecyclerView)) // ... perform an action indicating the item position .perform( RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>( hasDescendant(withText(containsString("Your order total is"))), click() ) )
matched View Holder. scrollToPosition() Scrolls to a specific position. actionOnHolderItem() Performs a View Action on a matched View Holder. actionOnItem() Performs a View Action on a matched View. actionOnItemAtPosition() Performs a ViewAction on a view at a specific position. More RecyclerViewActions
matched View Holder. scrollToPosition() Scrolls to a specific position. actionOnHolderItem() Performs a View Action on a matched View Holder. actionOnItem() Performs a View Action on a matched View. actionOnItemAtPosition() Performs a ViewAction on a view at a specific position. That’s it for Espresso… 🤓 More RecyclerViewActions
or device • Generates pseudo-random streams of events such as clicks, touches, or gestures, as well as a number of system-level events • Use it to stress-test applications that you are developing, in a random yet repeatable manner
notification, test completion, and final results. # Level 1 provides more details about the test as it runs, such as individual events being sent to your activities. Verbosity levels
notification, test completion, and final results. # Level 1 provides more details about the test as it runs, such as individual events being sent to your activities. # Level 2 provides more detailed setup information such as activities selected or not selected for testing. Verbosity levels
beyond startup notification, test completion, and final results. # Level 1 provides more details about the test as it runs, such as individual events being sent to your activities. # Level 2 provides more detailed setup information such as activities selected or not selected for testing. adb shell monkey -p com.example.app -v -v -v 500
beyond startup notification, test completion, and final results. # Level 1 provides more details about the test as it runs, such as individual events being sent to your activities. # Level 2 provides more detailed setup information such as activities selected or not selected for testing. adb shell monkey -p com.example.app -v -v -v 500
Basic navigation events adb shell monkey --pct-nav 100 500 # "Major" navigation events like # center button in a 5-way pad, the back key, or the menu key adb shell monkey --pct-majornav 100 500 Additional monkey options
Basic navigation events adb shell monkey --pct-nav 100 500 # "Major" navigation events like # center button in a 5-way pad, the back key, or the menu key adb shell monkey --pct-majornav 100 500 # System events # Home, Back, Start Call, End Call, Volume controls adb shell monkey --pct-syskeys 100 500 Additional monkey options
Basic navigation events adb shell monkey --pct-nav 100 500 # "Major" navigation events like # center button in a 5-way pad, the back key, or the menu key adb shell monkey --pct-majornav 100 500 # System events # Home, Back, Start Call, End Call, Volume controls adb shell monkey --pct-syskeys 100 500 # Will launch your app via startActivity() adb shell monkey --pct-appswitch 100 500 Additional monkey options