• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<p>
2    This sample is the test application for the <a href="../Alarm/index.html">Alarm</a>
3    sample application. It tests the application's <code>AlarmService</code> service.
4</p>
5<p>
6    The test application uses the
7    <a href="../../../reference/android/test/ServiceTestCase.html">
8    <code>ServiceTestCase</code></a>  test case class,
9    which extends the JUnit <a href="../../../reference/junit/framework/TestCase.html">
10    <code>TestCase</code></a> class. The test runner is
11    <a href="../../../reference/android/test/InstrumentationTestRunner.html">
12    <code>InstrumentationTestRunner</code></a>.
13</p>
14<p>
15    The application shows how to set up a test application project,
16    how to create the <a href="AndroidManifest.html"><code>AndroidManifest.xml</code></a>
17    file for a test application, and how to set up a test case class for a service. The
18    test case class, <a href="src/com/android/example/newalarm/ServiceAlarmTest.html">
19    <code>AlarmServiceTest</code></a>, contains tests that demonstrate the following
20    Android test patterns:
21</p>
22    <ul>
23        <li>
24            Test setup: The <code>setUp()</code> method re-initializes the state of the
25            service under test before each test is run.
26        </li>
27        <li>
28            Service start: The <code>Service.testServiceCreate()</code> test confirms that the
29            service starts correctly and initializes the variables it needs to provide its
30            services.
31        </li>
32    </ul>
33<p>
34    The <a href="AndroidManifest.html">manifest</a> declares an <code>&lt;instrumentation&gt;</code>
35    element that links the test application with the application under test. Specifically, the
36    element's <code>android:name</code> attribute specifies <code>InstrumentationTestRunner</code>
37    as the instrumentation to use. The <code>android:targetPackage</code> attribute specifies
38    <code>com.android.example.newalarm</code> as the name of the Android package that contains the
39    service under test.
40</p>
41<p class="note">
42    <strong>Note:</strong> <code>AlarmServiceTest.java</code> uses the Java package name
43    <code>com.example.android.newalarm</code>, which is the same package used by service under
44    test, <code>AlarmService.java</code>. This allows the test class to access members in the
45    service under test that are defined with package visibility. To prevent conflicts, though,
46    the generated java file <code>R.java</code> for <code>AlarmServiceTest</code> uses the
47    Java package name <code>com.example.android.newalarm.test</code>. For the same reason, the
48    Android package name for the test application (specified in the manifest file), is
49    <code>com.example.android.newalarm.test</code>.
50</p>
51