This sample is the test application for the Activity Testing tutorial. It tests the Spinner example application.
The test application uses the
ActivityInstrumentationTestCase2
test case class,
which extends both Android instrumentation and the JUnit
TestCase
class. The test runner is InstrumentationTestRunner
.
The application shows how to set up a test application project,
how to create the AndroidManifest.xml
file for a test application, and how to set up a test case class for a test fixture. The
test case class, SpinnerActivityTest
,
contains tests that demonstrate the following Android test patterns:
setUp()
method re-initializes the state of the application under test
before each test is run.
testPreconditions()
method demonstrates how to
test that the application under test is properly initialized prior to running the
test fixture.
testSpinnerUI()
method demonstrates how to send keystrokes
to the activity under test and then test the result.
testStateDestroy()
and testStatePause()
methods demonstrate how to use instrumentation to trigger stages in the lifecycle of the activity under test.
The manifest declares an <instrumentation>
element
that links the test application with the application under test. Specifically, the
element's android:name
attribute specifies InstrumentationTestRunner
as the
instrumentation to use. The android:targetPackage
attribute specifies
com.android.example.spinner
as the name of the Android package that contains the
application under test.