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