This sample is the test application for the Alarm
sample application. It tests the application's AlarmService service.
The test application uses the
ServiceTestCase test case class,
which extends 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 service. The
test case class,
AlarmServiceTest, contains tests that demonstrate the following
Android test patterns:
setUp() method re-initializes the state of the
service under test before each test is run.
Service.testServiceCreate() test confirms that the
service starts correctly and initializes the variables it needs to provide its
services.
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.newalarm as the name of the Android package that contains the
service under test.
Note: AlarmServiceTest.java uses the Java package name
com.example.android.newalarm, which is the same package used by service under
test, AlarmService.java. This allows the test class to access members in the
service under test that are defined with package visibility. To prevent conflicts, though,
the generated java file R.java for AlarmServiceTest uses the
Java package name com.example.android.newalarm.test. For the same reason, the
Android package name for the test application (specified in the manifest file), is
com.example.android.newalarm.test.