page.title=Automating User Interface Tests page.tags=testing page.image=images/testing/UIAutomatorViewer.png trainingnavtop=true startpage=true @jd:body <div id="tb-wrapper"> <div id="tb"> <h2> You should also read </h2> <ul> <li> <a href="{@docRoot}tools/testing-support-library/index.html">Testing Support Library</a> </li> </ul> </div> </div> <p>User interface (UI) testing lets you ensure that your app meets its functional requirements and achieves a high standard of quality such that it is more likely to be successfully adopted by users.</p> <p>One approach to UI testing is to simply have a human tester perform a set of user operations on the target app and verify that it is behaving correctly. However, this manual approach can be time-consuming, tedious, and error-prone. A more efficient approach is to write your UI tests such that user actions are performed in an automated way. The automated approach allows you to run your tests quickly and reliably in a repeatable manner.</p> <p class="note"><strong>Note: </strong>It is strongly encouraged that you use <a href="{@docRoot}studio/index.html">Android Studio</a> for building your test apps, because it provides project setup, library inclusion, and packaging conveniences. This class assumes you are using Android Studio.</p> <p>To automate UI tests with Android Studio, you implement your test code in a separate Android test folder ({@code src/androidTest/java}). The <a href="{@docRoot}tools/building/plugin-for-gradle.html">Android Plug-in for Gradle</a> builds a test app based on your test code, then loads the test app on the same device as the target app. In your test code, you can use UI testing frameworks to simulate user interactions on the target app, in order to perform testing tasks that cover specific usage scenarios.</p> <p>For testing Android apps, you typically create these types of automated UI tests:</p> <ul> <li><em>UI tests that span a single app:</em> This type of test verifies that the target app behaves as expected when a user performs a specific action or enters a specific input in its activities. It allows you to check that the target app returns the correct UI output in response to user interactions in the app’s activities. UI testing frameworks like Espresso allow you to programmatically simulate user actions and test complex intra-app user interactions.</li> <li><em>UI tests that span multiple apps:</em> This type of test verifies the correct behavior of interactions between different user apps or between user apps and system apps. For example, you might want to test that your camera app shares images correctly with a 3rd-party social media app, or with the default Android Photos app. UI testing frameworks that support cross-app interactions, such as UI Automator, allow you to create tests for such scenarios.</li> </ul> <p>The lessons in this class teach you how to use the tools and APIs in the <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a> to build these types of automated tests. Before you begin building tests using these APIs, you must install the Android Testing Support Library, as described in <a href="{@docRoot}tools/testing-support-library/index.html#setup">Downloading the Android Testing Support Library</a>.</p> <h2>Lessons</h2> <dl> <dt><strong><a href="espresso-testing.html"> Testing UI for a Single App</a></strong></dt> <dd>Learn how to test UI in a single app by using the Espresso testing framework.</dd> <dt><strong><a href="uiautomator-testing.html"> Testing UI for Multiple Apps</a></strong></dt> <dd>Learn how to test UI in multiple apps by using the UI Automator testing framework.</dd> </dl>