• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=What To Test
2parent.title=Testing
3parent.link=index.html
4@jd:body
5<p>
6    As you develop Android applications, knowing what to test is as important as knowing how to
7    test. This document lists some most common Android-related situations that you should consider
8    when you test, even at the unit test level. This is not an exhaustive list, and you consult the
9    documentation for the features that you use for more ideas. The
10    <a href="http://groups.google.com/group/android-developers">android-developers</a> Google Groups
11    site is another resource for information about testing.
12</p>
13<h2 id="Tests">Ideas for Testing</h2>
14<p>
15    The following sections are organized by behaviors or situations that you should test. Each
16    section contains a scenario that further illustrates the situation and the test or tests you
17    should do.
18</p>
19<h4>Change in orientation</h4>
20<p>
21    For devices that support multiple orientations, Android detects a change in orientation when
22    the user turns the device so that the display is "landscape" (long edge is horizontal) instead
23    of "portrait" (long edge is vertical).
24</p>
25<p>
26    When Android detects a change in orientation, its default behavior is to destroy and then
27    re-start the foreground Activity. You should consider testing the following:
28</p>
29<ul>
30    <li>
31        Is the screen re-drawn correctly? Any custom UI code you have should handle changes in the
32        orientation.
33    </li>
34    <li>
35        Does the application maintain its state? The Activity should not lose anything that the
36        user has already entered into the UI. The application should not "forget" its place in the
37        current transaction.
38    </li>
39</ul>
40<h4>Change in configuration</h4>
41<p>
42    A situation that is more general than a change in orientation is a change in the device's
43    configuration, such as a change in the availability of a keyboard or a change in system
44    language.
45</p>
46<p>
47    A change in configuration also triggers the default behavior of destroying and then restarting
48    the foreground Activity. Besides testing that the application maintains the UI and its
49    transaction state, you should also test that the application updates itself to respond
50    correctly to the new configuration.
51</p>
52<h4>Battery life</h4>
53<p>
54    Mobile devices primarily run on battery power. A device has finite "battery budget", and when it
55    is gone, the device is useless until it is recharged. You need to write your application to
56    minimize battery usage, you need to test its battery performance, and you need to test the
57    methods that manage battery usage.
58</p>
59<p>
60    Techniques for minimizing battery usage were presented at the 2010 Google I/O conference in the
61    presentation
62    <a href="http://code.google.com/events/io/2009/sessions/CodingLifeBatteryLife.html">
63    Coding for Life -- Battery Life, That Is</a>. This presentation describes the impact on battery
64    life of various operations, and the ways you can design your application to minimize these
65    impacts. When you code your application to reduce battery usage, you also write the
66    appropriate unit tests.
67</p>
68<h4>Dependence on external resources</h4>
69<p>
70    If your application depends on network access, SMS, Bluetooth, or GPS, then you should
71    test what happens when the resource or resources are not available.
72</p>
73<p>
74    For example, if your application uses the network,it can notify the user if access is
75    unavailable, or disable network-related features, or do both. For GPS, it can switch to
76    IP-based location awareness. It can also wait for WiFi access before doing large data transfers,
77    since WiFi transfers maximize battery usage compared to transfers over 3G or EDGE.
78</p>
79<p>
80    You can use the emulator to test network access and bandwidth. To learn more, please see
81    <a href="{@docRoot}guide/developing/tools/emulator.html#netspeed">Network Speed Emulation</a>.
82    To test GPS, you can use the emulator console and {@link android.location.LocationManager}. To
83    learn more about the emulator console, please see
84    <a href="{@docRoot}guide/developing/tools/emulator.html#console">
85    Using the Emulator Console</a>.
86</p>
87