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 android-developers Google Groups site is another resource for information about testing.
Ideas for Testing
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.
Change in orientation
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).
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:
- Is the screen re-drawn correctly? Any custom UI code you have should handle changes in the orientation.
- 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.
Change in configuration
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.
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.
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.
Techniques for minimizing battery usage were presented at the 2010 Google I/O conference in the presentation Coding for Life -- Battery Life, That Is. 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.
Dependence on external resources
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.
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.
You can use the emulator to test network access and bandwidth. To learn more, please see
Network Speed Emulation.
To test GPS, you can use the emulator console and
learn more about the emulator console, please see
Using the Emulator Console.