summaryrefslogtreecommitdiffstats
path: root/docs/html/guide/topics/testing/what_to_test.jd
blob: e8a27da8ce0a647916aa14ff711c027fc62b1050 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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>