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