Home | History | Annotate | Download | only in ui-testing
      1 page.title=Automating User Interface Tests
      2 page.tags=testing
      3 
      4 trainingnavtop=true
      5 startpage=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
     24 and achieves a high standard of quality such that it is more likely to be successfully adopted by
     25 users.</p>
     26 
     27 <p>One approach to UI testing is to simply have a human tester perform a set of user operations on
     28 the target app and verify that it is behaving correctly. However, this manual approach can be
     29 time-consuming, tedious, and error-prone. A more efficient approach is to write your UI
     30 tests such that user actions are performed in an automated way. The automated approach allows
     31 you 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
     35 building your test apps, because it provides project setup, library inclusion, and packaging
     36 conveniences. 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
     39 Android test folder ({@code src/androidTest/java}). The
     40 <a href="{@docRoot}tools/building/plugin-for-gradle.html">Android
     41 Plug-in for Gradle</a> builds a test app based on your test code, then loads the test app on the
     42 same device as the target app. In your test code, you can use UI testing frameworks to
     43 simulate user interactions on the target app, in order to perform testing tasks that cover specific
     44 usage 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
     50 as expected when a user performs a specific action or enters a specific input in its activities.
     51 It allows you to check that the target app returns the correct UI output in response
     52 to user interactions in the apps activities. UI testing frameworks like Espresso allow you to
     53 programmatically 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
     55 interactions between different user apps or between user apps and system apps. For example, you
     56 might want to test that your camera app shares images correctly with a 3rd-party social media app,
     57 or with the default Android Photos app. UI testing frameworks that support cross-app interactions,
     58 such 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>
     63 to build these types of automated tests. Before you begin building tests using these
     64 APIs, 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
     66 Testing Support Library</a>.</p>
     67 
     68 <h2>Lessons</h2>
     69 <dl>
     70   <dt><strong><a href="espresso-testing.html">
     71 Testing 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">
     74 Testing 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>