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