Skip to content

Commit 527cfd6

Browse files
Joe Malinddougherty
authored andcommitted
Doc change: cherry-pick from master: Files for the Spinner and SpinnerTest sample applications...
Change-Id: Ic4a1d28ea821ab7e35255d5a62ca0978cb9155ba
1 parent 2f0b1c1 commit 527cfd6

File tree

4 files changed

+71
-30
lines changed

4 files changed

+71
-30
lines changed

samples/Spinner/_index.html

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
<p>
2-
This sample is the application under test for the
3-
<a href="../../../resources/tutorials/testing/activity_test.html">Activity
4-
Testing Tutorial</a>. It contains a single Activity that displays a
5-
Spinner widget backed by an array of strings containing the names of the planets
6-
in the Solar System. When an entry is selected from the Spinner, the entry is
7-
displayed in a text box.
2+
This sample is a simple application that serves as an application under test
3+
for the <a href="../SpinnerTest/index.html">SpinnerTest</a> test application example.
84
</p>
95
<p>
10-
An important part of this application is state management. When the application
11-
is first run, the spinner widget displays a default selection of
12-
&quot;Earth&quot;. Thereafter, the application saves a selection as soon as it
6+
This application illustrates basic state management across the Android application life cycle,
7+
mainly for the purpose of highlighting common patterns of Activity testing. When the application
8+
is first run, the spinner widget displays a default selection of &quot;Earth&quot;.
9+
Thereafter, the application saves a selection as soon as it
1310
is made. The application remembers the selection from invocation to invocation, even
1411
if the device reboots.
1512
</p>
1613
<p>
17-
For more information about this application, see the Activity Testing Tutorial.
18-
The test application for this application is in the <a
19-
href="../SpinnerTest/index.html">SpinnerTest</a> sample application.
14+
The test application <a href="../SpinnerTest/index.html">SpinnerTest</a>
15+
shows you how to set up tests to monitor and prevent code regressions in the
16+
management of state across invocations and power cycles.
17+
</p>
18+
<p>
19+
For more information about this application, see the
20+
<a href="../../../resources/tutorials/testing/activity_test.html">Activity Testing</a> tutorial.
2021
</p>
21-
22-
<img alt="The Spinner application" src="../images/testing/spinner_main_screen.png" />

samples/SpinnerTest/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package="com.android.example.spinner.test"
2727
android:versionCode="1"
2828
android:versionName="1.0">
29+
<uses-sdk android:minSdkVersion="3" />
2930
<application android:label="@string/app_name">
3031
<!--
3132
this package needs to link against the android.test library,

samples/SpinnerTest/_index.html

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,52 @@
11
<p>
2-
This sample is the test application for the
3-
<a href="../../../resources/tutorials/testing/activity_test.html">Activity
4-
Testing Tutorial</a>. Refer to the tutorial text for a full explanation
5-
of this sample code.
2+
This sample is the test application for the
3+
<a href="../../../resources/tutorials/testing/activity_test.html">Activity
4+
Testing</a> tutorial. It tests the <a href="../Spinner/index.html">Spinner</a> example
5+
application.
66
</p>
77
<p>
8-
This application does not have an Android GUI.
8+
The test application uses the
9+
<a href="../../../reference/android/test/ActivityInstrumentationTestCase2.html"><code>ActivityInstrumentationTestCase2</code></a>
10+
test case class,
11+
which extends both <a href="../../../reference/android/app/Instrumentation">Android instrumentation</a> and the JUnit
12+
<a href="../../../reference/junit/framework/TestCase.html"><code>TestCase</code></a>
13+
class. The test runner is <a href="../../../reference/android/test/InstrumentationTestRunner.html"><code>InstrumentationTestRunner</code></a>.
914
</p>
15+
<p>
16+
The application shows how to set up a test application project,
17+
how to create the <a href="AndroidManifest.html"><code>AndroidManifest.xml</code></a>
18+
file for a test application, and how to set up a test case class for a test fixture. The
19+
test case class, <a href="src/com/android/example/spinner/test/SpinnerActivityTest.html"><code>SpinnerActivityTest</code></a>,
20+
contains tests that demonstrate the following Android test patterns:
21+
</p>
22+
<ul>
23+
<li>
24+
Test setup: The <code>setUp()</code> method re-initializes the state of the application under test
25+
before each test is run.
26+
</li>
27+
<li>
28+
Initial conditions: The <code>testPreconditions()</code> method demonstrates how to
29+
test that the application under test is properly initialized prior to running the
30+
test fixture.
31+
</li>
32+
<li>
33+
UI interaction: The <code>testSpinnerUI()</code> method demonstrates how to send keystrokes
34+
to the activity under test and then test the result.
35+
</li>
36+
<li>
37+
Application control using instrumentation: The <code>testStateDestroy()</code> and <code>testStatePause()</code>
38+
methods demonstrate how to use instrumentation to trigger stages in the lifecycle of the activity under test.
39+
</li>
40+
</ul>
41+
<p>
42+
The <a href="AndroidManifest.html">manifest</a> declares an <code>&lt;instrumentation&gt;</code> element
43+
that links the test application with the application under test. Specifically, the
44+
element's <code>android:name</code> attribute specifies <code>InstrumentationTestRunner</code> as the
45+
instrumentation to use. The <code>android:targetPackage</code> attribute specifies
46+
<code>com.android.example.spinner</code> as the name of the Android package that contains the
47+
application under test.
48+
</p>
49+
<img alt="The initial user interface for the Spinner sample application" style="height:230px;"
50+
src="../images/SpinnerTest1.png"/>
51+
<img alt="The JUnit view in Eclipse with ADT, showing a successful test run of SpinnerTest" style="height:230px;"
52+
src="../images/SpinnerTest2.png"/>

samples/SpinnerTest/src/com/android/example/spinner/test/SpinnerActivityTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
import android.widget.SpinnerAdapter;
2727
import android.widget.TextView;
2828

29-
/**
29+
/*
3030
* Tests the example application Spinner. Uses the instrumentation test class
31-
* {@link ActivityInstrumentationTestCase2} as its base class. The tests include
32-
* <ol>
33-
* <li>test initial conditions</li>
34-
* <li>test the UI</li>
35-
* <li>state management - preserving state after the app is shut down and restarted, preserving
36-
* state after the app is hidden (paused) and re-displayed (resumed)</li>
37-
* </ol>
31+
* ActivityInstrumentationTestCase2 as its base class. The tests include
32+
* - test initial conditions
33+
* - test the UI
34+
* - state management - preserving state after the app is shut down and restarted, preserving
35+
* state after the app is hidden (paused) and re-displayed (resumed)
3836
*
3937
* Demonstrates the use of JUnit setUp() and assert() methods.
4038
*/
@@ -91,7 +89,7 @@ public class SpinnerActivityTest extends ActivityInstrumentationTestCase2<Spinne
9189

9290
private SpinnerAdapter mPlanetData;
9391

94-
/**
92+
/*
9593
* Constructor for the test class. Required by Android test classes. The constructor
9694
* must call the super constructor, providing the Android package name of the app under test
9795
* and the Java class name of the activity in that application that handles the MAIN intent.
@@ -101,7 +99,7 @@ public SpinnerActivityTest() {
10199
super("com.android.example.spinner", SpinnerActivity.class);
102100
}
103101

104-
/**
102+
/*
105103
* Sets up the test environment before each test.
106104
* @see android.test.ActivityInstrumentationTestCase2#setUp()
107105
*/
@@ -140,7 +138,7 @@ protected void setUp() throws Exception {
140138

141139
}
142140

143-
/**
141+
/*
144142
* Tests the initial values of key objects in the app under test, to ensure the initial
145143
* conditions make sense. If one of these is not initialized correctly, then subsequent
146144
* tests are suspect and should be ignored.

0 commit comments

Comments
 (0)