| Quddus Chong | 7639e73 | 2015-03-05 13:16:24 -0800 | [diff] [blame] | 1 | page.title=Automating User Interface Tests |
| 2 | page.tags=testing |
| Quddus Chong | e3f6c81 | 2015-08-26 14:16:05 -0700 | [diff] [blame] | 3 | page.image=images/testing/UIAutomatorViewer.png |
| Quddus Chong | 7639e73 | 2015-03-05 13:16:24 -0800 | [diff] [blame] | 4 | |
| 5 | trainingnavtop=true |
| 6 | startpage=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 Chong | 54dee34 | 2015-04-03 17:06:28 -0700 | [diff] [blame] | 18 | <a href="{@docRoot}tools/testing-support-library/index.html">Testing Support Library</a> |
| Quddus Chong | 7639e73 | 2015-03-05 13:16:24 -0800 | [diff] [blame] | 19 | </li> |
| 20 | </ul> |
| 21 | </div> |
| 22 | </div> |
| 23 | |
| 24 | <p>User interface (UI) testing lets you ensure that your app meets its functional requirements |
| 25 | and achieves a high standard of quality such that it is more likely to be successfully adopted by |
| 26 | users.</p> |
| 27 | |
| 28 | <p>One approach to UI testing is to simply have a human tester perform a set of user operations on |
| 29 | the target app and verify that it is behaving correctly. However, this manual approach can be |
| 30 | time-consuming, tedious, and error-prone. A more efficient approach is to write your UI |
| 31 | tests such that user actions are performed in an automated way. The automated approach allows |
| 32 | you 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.com | 89d1170 | 2016-05-14 19:20:00 -0700 | [diff] [blame] | 35 | <a href="{@docRoot}studio/index.html">Android Studio</a> for |
| Quddus Chong | 7639e73 | 2015-03-05 13:16:24 -0800 | [diff] [blame] | 36 | building your test apps, because it provides project setup, library inclusion, and packaging |
| 37 | conveniences. 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 |
| 40 | Android test folder ({@code src/androidTest/java}). The |
| 41 | <a href="{@docRoot}tools/building/plugin-for-gradle.html">Android |
| 42 | Plug-in for Gradle</a> builds a test app based on your test code, then loads the test app on the |
| 43 | same device as the target app. In your test code, you can use UI testing frameworks to |
| 44 | simulate user interactions on the target app, in order to perform testing tasks that cover specific |
| 45 | usage 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 |
| 51 | as expected when a user performs a specific action or enters a specific input in its activities. |
| 52 | It allows you to check that the target app returns the correct UI output in response |
| 53 | to user interactions in the app’s activities. UI testing frameworks like Espresso allow you to |
| 54 | programmatically 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 |
| 56 | interactions between different user apps or between user apps and system apps. For example, you |
| 57 | might want to test that your camera app shares images correctly with a 3rd-party social media app, |
| 58 | or with the default Android Photos app. UI testing frameworks that support cross-app interactions, |
| 59 | such 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 Chong | 54dee34 | 2015-04-03 17:06:28 -0700 | [diff] [blame] | 63 | <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a> |
| Quddus Chong | 7639e73 | 2015-03-05 13:16:24 -0800 | [diff] [blame] | 64 | to build these types of automated tests. Before you begin building tests using these |
| 65 | APIs, you must install the Android Testing Support Library, as described in |
| Quddus Chong | 54dee34 | 2015-04-03 17:06:28 -0700 | [diff] [blame] | 66 | <a href="{@docRoot}tools/testing-support-library/index.html#setup">Downloading the Android |
| Quddus Chong | 7639e73 | 2015-03-05 13:16:24 -0800 | [diff] [blame] | 67 | Testing Support Library</a>.</p> |
| 68 | |
| 69 | <h2>Lessons</h2> |
| 70 | <dl> |
| 71 | <dt><strong><a href="espresso-testing.html"> |
| 72 | Testing 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"> |
| 75 | Testing UI for Multiple Apps</a></strong></dt> |
| Quddus Chong | 4bc762a | 2015-04-07 16:42:24 -0700 | [diff] [blame] | 76 | <dd>Learn how to test UI in multiple apps by using the UI Automator testing framework.</dd> |
| Quddus Chong | 7639e73 | 2015-03-05 13:16:24 -0800 | [diff] [blame] | 77 | </dl> |