Android Writing UI tests - Android

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Focus of this document is to represent goals and ways how to write android UI and integration tests. Espresso and UIAutomator are provided by Google so focus should be around these tools and their respective wrappers e.g. Appium, Spoon etc.

Syntax

  • Idling resource
  • String getName() - Returns the name of the idling resource(used for logging and idempotency of registration).
  • boolean isIdleNow() - Returns true if resource is currently idle.
  • void registerIdleTransitionCallback(IdlingResource.ResourceCallback callback) - Registers the given IdlingResource.ResourceCallback with the resource

Remarks

JUnit rules:

As you can see in MockWebServer example and ActivityTestRule they all fall under category of JUnit rules which you can create yourself which then should be executed for each test defining its behaviour @see: https://github.com/junit-team/junit4/wiki/rules

Appium

Parameters

Since parameters have some issues placing them here until documentation bug is resolved:

ParameterDetails
Class activityClasswhich activity to start
initialTouchModeshould the activity be placed in touch mode on start: https://android-developers.blogspot.de/2008/12/touch-mode.html
launchActivitytrue if the Activity should be launched once per Test method. It will be launched before the first Before method, and terminated after the last After method.


Got any Android Question?