Google’s UI Automator library is a UI testing framework that enables functional testing of Android applications, agnostic of the running application. UI Automator provides APIs to interact with the user interface elements that are visible on the screen at any given time. UI Automator allows developers to automate tests that interact with the user interface of an Android application and verify that the application behaves as expected.
UI Automator does not need dependencies on any application-specific code. UI Automator tests can also be run with
AndroidJUnitRunner, enabling seamless integration with existing JUnit test suites. UI Automator also offers significant advantages to Android developers over other frameworks like Appium, as tests are written in native Kotlin or Java, leveraging UI Automator’s rich API.
UI Automator runs from a separate process on device, which requires developers to build a separate APK for testing. Usually, this can be done relatively easily with a separate testing module.
To assist with writing tests, Google provides a tool, uiautomatorviewer, to make finding views/identifiers and writing tests with those views far easier. The tool allows for a snapshot to be taken of the connected device or emulator, then outputs the entire view tree with rich detail about each view, as well as ids and attributes associated with the view.
An example of a snapshot generated with uiautomatorviewer from a running Android emulator. Agnostic of which application is running, uiautomatorviewer can output detailed information about the view tree currently on screen