Doc Change: Files for the Spinner and SpinnerTest sample applications, part of Activity Testing tutorial
Change-Id: If9b6f214cdad870257efc34193eed846cde2ec47
This commit is contained in:
@@ -1,22 +1,21 @@
|
|||||||
<p>
|
<p>
|
||||||
This sample is the application under test for the
|
This sample is a simple application that serves as an application under test
|
||||||
<a href="../../../resources/tutorials/testing/activity_test.html">Activity
|
for the <a href="../SpinnerTest/index.html">SpinnerTest</a> test application example.
|
||||||
Testing Tutorial</a>. It contains a single Activity that displays a
|
|
||||||
Spinner widget backed by an array of strings containing the names of the planets
|
|
||||||
in the Solar System. When an entry is selected from the Spinner, the entry is
|
|
||||||
displayed in a text box.
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
An important part of this application is state management. When the application
|
This application illustrates basic state management across the Android application life cycle,
|
||||||
is first run, the spinner widget displays a default selection of
|
mainly for the purpose of highlighting common patterns of Activity testing. When the application
|
||||||
"Earth". Thereafter, the application saves a selection as soon as it
|
is first run, the spinner widget displays a default selection of "Earth".
|
||||||
|
Thereafter, the application saves a selection as soon as it
|
||||||
is made. The application remembers the selection from invocation to invocation, even
|
is made. The application remembers the selection from invocation to invocation, even
|
||||||
if the device reboots.
|
if the device reboots.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
For more information about this application, see the Activity Testing Tutorial.
|
The test application <a href="../SpinnerTest/index.html">SpinnerTest</a>
|
||||||
The test application for this application is in the <a
|
shows you how to set up tests to monitor and prevent code regressions in the
|
||||||
href="../SpinnerTest/index.html">SpinnerTest</a> sample application.
|
management of state across invocations and power cycles.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
For more information about this application, see the
|
||||||
|
<a href="../../../resources/tutorials/testing/activity_test.html">Activity Testing</a> tutorial.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<img alt="The Spinner application" src="../images/testing/spinner_main_screen.png" />
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
package="com.android.example.spinner.test"
|
package="com.android.example.spinner.test"
|
||||||
android:versionCode="1"
|
android:versionCode="1"
|
||||||
android:versionName="1.0">
|
android:versionName="1.0">
|
||||||
|
<uses-sdk android:minSdkVersion="3" />
|
||||||
<application android:label="@string/app_name">
|
<application android:label="@string/app_name">
|
||||||
<!--
|
<!--
|
||||||
this package needs to link against the android.test library,
|
this package needs to link against the android.test library,
|
||||||
|
|||||||
@@ -1,9 +1,52 @@
|
|||||||
<p>
|
<p>
|
||||||
This sample is the test application for the
|
This sample is the test application for the
|
||||||
<a href="../../../resources/tutorials/testing/activity_test.html">Activity
|
<a href="../../../resources/tutorials/testing/activity_test.html">Activity
|
||||||
Testing Tutorial</a>. Refer to the tutorial text for a full explanation
|
Testing</a> tutorial. It tests the <a href="../Spinner/index.html">Spinner</a> example
|
||||||
of this sample code.
|
application.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
This application does not have an Android GUI.
|
The test application uses the
|
||||||
|
<a href="../../../reference/android/test/ActivityInstrumentationTestCase2.html"><code>ActivityInstrumentationTestCase2</code></a>
|
||||||
|
test case class,
|
||||||
|
which extends both <a href="../../../reference/android/app/Instrumentation">Android instrumentation</a> and the JUnit
|
||||||
|
<a href="../../../reference/junit/framework/TestCase.html"><code>TestCase</code></a>
|
||||||
|
class. The test runner is <a href="../../../reference/android/test/InstrumentationTestRunner.html"><code>InstrumentationTestRunner</code></a>.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
The application shows how to set up a test application project,
|
||||||
|
how to create the <a href="AndroidManifest.html"><code>AndroidManifest.xml</code></a>
|
||||||
|
file for a test application, and how to set up a test case class for a test fixture. The
|
||||||
|
test case class, <a href="src/com/android/example/spinner/test/SpinnerActivityTest.html"><code>SpinnerActivityTest</code></a>,
|
||||||
|
contains tests that demonstrate the following Android test patterns:
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
Test setup: The <code>setUp()</code> method re-initializes the state of the application under test
|
||||||
|
before each test is run.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Initial conditions: The <code>testPreconditions()</code> method demonstrates how to
|
||||||
|
test that the application under test is properly initialized prior to running the
|
||||||
|
test fixture.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
UI interaction: The <code>testSpinnerUI()</code> method demonstrates how to send keystrokes
|
||||||
|
to the activity under test and then test the result.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Application control using instrumentation: The <code>testStateDestroy()</code> and <code>testStatePause()</code>
|
||||||
|
methods demonstrate how to use instrumentation to trigger stages in the lifecycle of the activity under test.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p>
|
||||||
|
The <a href="AndroidManifest.html">manifest</a> declares an <code><instrumentation></code> element
|
||||||
|
that links the test application with the application under test. Specifically, the
|
||||||
|
element's <code>android:name</code> attribute specifies <code>InstrumentationTestRunner</code> as the
|
||||||
|
instrumentation to use. The <code>android:targetPackage</code> attribute specifies
|
||||||
|
<code>com.android.example.spinner</code> as the name of the Android package that contains the
|
||||||
|
application under test.
|
||||||
|
</p>
|
||||||
|
<img alt="The initial user interface for the Spinner sample application" style="height:230px;"
|
||||||
|
src="../images/SpinnerTest1.png"/>
|
||||||
|
<img alt="The JUnit view in Eclipse with ADT, showing a successful test run of SpinnerTest" style="height:230px;"
|
||||||
|
src="../images/SpinnerTest2.png"/>
|
||||||
|
|||||||
@@ -26,15 +26,13 @@ import android.widget.Spinner;
|
|||||||
import android.widget.SpinnerAdapter;
|
import android.widget.SpinnerAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Tests the example application Spinner. Uses the instrumentation test class
|
* Tests the example application Spinner. Uses the instrumentation test class
|
||||||
* {@link ActivityInstrumentationTestCase2} as its base class. The tests include
|
* ActivityInstrumentationTestCase2 as its base class. The tests include
|
||||||
* <ol>
|
* - test initial conditions
|
||||||
* <li>test initial conditions</li>
|
* - test the UI
|
||||||
* <li>test the UI</li>
|
* - state management - preserving state after the app is shut down and restarted, preserving
|
||||||
* <li>state management - preserving state after the app is shut down and restarted, preserving
|
* state after the app is hidden (paused) and re-displayed (resumed)
|
||||||
* state after the app is hidden (paused) and re-displayed (resumed)</li>
|
|
||||||
* </ol>
|
|
||||||
*
|
*
|
||||||
* Demonstrates the use of JUnit setUp() and assert() methods.
|
* Demonstrates the use of JUnit setUp() and assert() methods.
|
||||||
*/
|
*/
|
||||||
@@ -91,7 +89,7 @@ public class SpinnerActivityTest extends ActivityInstrumentationTestCase2<Spinne
|
|||||||
|
|
||||||
private SpinnerAdapter mPlanetData;
|
private SpinnerAdapter mPlanetData;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Constructor for the test class. Required by Android test classes. The constructor
|
* Constructor for the test class. Required by Android test classes. The constructor
|
||||||
* must call the super constructor, providing the Android package name of the app under test
|
* must call the super constructor, providing the Android package name of the app under test
|
||||||
* and the Java class name of the activity in that application that handles the MAIN intent.
|
* and the Java class name of the activity in that application that handles the MAIN intent.
|
||||||
@@ -101,7 +99,7 @@ public class SpinnerActivityTest extends ActivityInstrumentationTestCase2<Spinne
|
|||||||
super("com.android.example.spinner", SpinnerActivity.class);
|
super("com.android.example.spinner", SpinnerActivity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Sets up the test environment before each test.
|
* Sets up the test environment before each test.
|
||||||
* @see android.test.ActivityInstrumentationTestCase2#setUp()
|
* @see android.test.ActivityInstrumentationTestCase2#setUp()
|
||||||
*/
|
*/
|
||||||
@@ -140,7 +138,7 @@ public class SpinnerActivityTest extends ActivityInstrumentationTestCase2<Spinne
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Tests the initial values of key objects in the app under test, to ensure the initial
|
* Tests the initial values of key objects in the app under test, to ensure the initial
|
||||||
* conditions make sense. If one of these is not initialized correctly, then subsequent
|
* conditions make sense. If one of these is not initialized correctly, then subsequent
|
||||||
* tests are suspect and should be ignored.
|
* tests are suspect and should be ignored.
|
||||||
|
|||||||
Reference in New Issue
Block a user