1page.title=Automating User Interface Tests 2page.tags=testing 3 4trainingnavtop=true 5startpage=true 6 7@jd:body 8 9<div id="tb-wrapper"> 10<div id="tb"> 11 <h2> 12 You should also read 13 </h2> 14 15 <ul> 16 <li> 17 <a href="{@docRoot}tools/testing-support-library/index.html">Testing Support Library</a> 18 </li> 19 </ul> 20</div> 21</div> 22 23<p>User interface (UI) testing lets you ensure that your app meets its functional requirements 24and achieves a high standard of quality such that it is more likely to be successfully adopted by 25users.</p> 26 27<p>One approach to UI testing is to simply have a human tester perform a set of user operations on 28the target app and verify that it is behaving correctly. However, this manual approach can be 29time-consuming, tedious, and error-prone. A more efficient approach is to write your UI 30tests such that user actions are performed in an automated way. The automated approach allows 31you to run your tests quickly and reliably in a repeatable manner.</p> 32 33<p class="note"><strong>Note: </strong>It is strongly encouraged that you use 34<a href="{@docRoot}sdk/installing/studio.html">Android Studio</a> for 35building your test apps, because it provides project setup, library inclusion, and packaging 36conveniences. This class assumes you are using Android Studio.</p> 37 38<p>To automate UI tests with Android Studio, you implement your test code in a separate 39Android test folder ({@code src/androidTest/java}). The 40<a href="{@docRoot}tools/building/plugin-for-gradle.html">Android 41Plug-in for Gradle</a> builds a test app based on your test code, then loads the test app on the 42same device as the target app. In your test code, you can use UI testing frameworks to 43simulate user interactions on the target app, in order to perform testing tasks that cover specific 44usage scenarios.</p> 45 46<p>For testing Android apps, you typically create these types of automated UI tests:</p> 47 48<ul> 49<li><em>UI tests that span a single app:</em> This type of test verifies that the target app behaves 50as expected when a user performs a specific action or enters a specific input in its activities. 51It allows you to check that the target app returns the correct UI output in response 52to user interactions in the app’s activities. UI testing frameworks like Espresso allow you to 53programmatically simulate user actions and test complex intra-app user interactions.</li> 54<li><em>UI tests that span multiple apps:</em> This type of test verifies the correct behavior of 55interactions between different user apps or between user apps and system apps. For example, you 56might want to test that your camera app shares images correctly with a 3rd-party social media app, 57or with the default Android Photos app. UI testing frameworks that support cross-app interactions, 58such as UI Automator, allow you to create tests for such scenarios.</li> 59</ul> 60 61<p>The lessons in this class teach you how to use the tools and APIs in the 62<a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a> 63to build these types of automated tests. Before you begin building tests using these 64APIs, you must install the Android Testing Support Library, as described in 65<a href="{@docRoot}tools/testing-support-library/index.html#setup">Downloading the Android 66Testing Support Library</a>.</p> 67 68<h2>Lessons</h2> 69<dl> 70 <dt><strong><a href="espresso-testing.html"> 71Testing UI for a Single App</a></strong></dt> 72 <dd>Learn how to test UI in a single app by using the Espresso testing framework.</dd> 73 <dt><strong><a href="uiautomator-testing.html"> 74Testing UI for Multiple Apps</a></strong></dt> 75 <dd>Learn how to test UI in multiple apps by using the UI Automator testing framework.</dd> 76</dl>