| page.title=What To Test |
| @jd:body |
| <p> |
| As you develop Android applications, knowing what to test is as important as knowing how to |
| test. This document lists some most common Android-related situations that you should consider |
| when you test, even at the unit test level. This is not an exhaustive list, and you consult the |
| documentation for the features that you use for more ideas. The |
| <a href="http://groups.google.com/group/android-developers">android-developers</a> Google Groups |
| site is another resource for information about testing. |
| </p> |
| <h2 id="Tests">Ideas for Testing</h2> |
| <p> |
| The following sections are organized by behaviors or situations that you should test. Each |
| section contains a scenario that further illustrates the situation and the test or tests you |
| should do. |
| </p> |
| <h4>Change in orientation</h4> |
| <p> |
| For devices that support multiple orientations, Android detects a change in orientation when |
| the user turns the device so that the display is "landscape" (long edge is horizontal) instead |
| of "portrait" (long edge is vertical). |
| </p> |
| <p> |
| When Android detects a change in orientation, its default behavior is to destroy and then |
| re-start the foreground Activity. You should consider testing the following: |
| </p> |
| <ul> |
| <li> |
| Is the screen re-drawn correctly? Any custom UI code you have should handle changes in the |
| orientation. |
| </li> |
| <li> |
| Does the application maintain its state? The Activity should not lose anything that the |
| user has already entered into the UI. The application should not "forget" its place in the |
| current transaction. |
| </li> |
| </ul> |
| <h4>Change in configuration</h4> |
| <p> |
| A situation that is more general than a change in orientation is a change in the device's |
| configuration, such as a change in the availability of a keyboard or a change in system |
| language. |
| </p> |
| <p> |
| A change in configuration also triggers the default behavior of destroying and then restarting |
| the foreground Activity. Besides testing that the application maintains the UI and its |
| transaction state, you should also test that the application updates itself to respond |
| correctly to the new configuration. |
| </p> |
| <h4>Battery life</h4> |
| <p> |
| Mobile devices primarily run on battery power. A device has finite "battery budget", and when it |
| is gone, the device is useless until it is recharged. You need to write your application to |
| minimize battery usage, you need to test its battery performance, and you need to test the |
| methods that manage battery usage. |
| </p> |
| <p> |
| Techniques for minimizing battery usage were presented at the 2010 Google I/O conference in the |
| presentation |
| <a href="http://code.google.com/events/io/2009/sessions/CodingLifeBatteryLife.html"> |
| Coding for Life -- Battery Life, That Is</a>. This presentation describes the impact on battery |
| life of various operations, and the ways you can design your application to minimize these |
| impacts. When you code your application to reduce battery usage, you also write the |
| appropriate unit tests. |
| </p> |
| <h4>Dependence on external resources</h4> |
| <p> |
| If your application depends on network access, SMS, Bluetooth, or GPS, then you should |
| test what happens when the resource or resources are not available. |
| </p> |
| <p> |
| For example, if your application uses the network,it can notify the user if access is |
| unavailable, or disable network-related features, or do both. For GPS, it can switch to |
| IP-based location awareness. It can also wait for WiFi access before doing large data transfers, |
| since WiFi transfers maximize battery usage compared to transfers over 3G or EDGE. |
| </p> |
| <p> |
| You can use the emulator to test network access and bandwidth. To learn more, please see |
| <a href="{@docRoot}guide/developing/tools/emulator.html#netspeed">Network Speed Emulation</a>. |
| To test GPS, you can use the emulator console and {@link android.location.LocationManager}. To |
| learn more about the emulator console, please see |
| <a href="{@docRoot}/guide/developing/tools/emulator.html#console"> |
| Using the Emulator Console</a>. |
| </p> |