blob: f6b31ad208f7d9bd0e9f1e2e581b8883f374d1e7 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.test;
18
19import android.app.Activity;
20
21import java.lang.reflect.Field;
22
23/**
24 * This class provides functional testing of a single activity. The activity under test will
25 * be created using the system infrastructure (by calling InstrumentationTestCase.launchActivity())
26 * and you will then be able to manipulate your Activity directly. Most of the work is handled
27 * automatically here by {@link #setUp} and {@link #tearDown}.
28 *
29 * <p>If you prefer an isolated unit test, see {@link android.test.ActivityUnitTestCase}.
30 *
31 * @deprecated new tests should be written using
32 * {@link android.test.ActivityInstrumentationTestCase2}, which provides more options for
33 * configuring the Activity under test
34 */
35@Deprecated
36public abstract class ActivityInstrumentationTestCase<T extends Activity>
37 extends ActivityTestCase {
38 String mPackage;
39 Class<T> mActivityClass;
40 boolean mInitialTouchMode = false;
41
42 /**
Andy Stadler72d5de72009-04-21 11:54:14 -070043 * <b>NOTE:</b> The parameter <i>pkg</i> must refer to the package identifier of the
44 * package hosting the activity to be launched, which is specified in the AndroidManifest.xml
45 * file. This is not necessarily the same as the java package name.
46 *
47 * @param pkg The package hosting the activity to be launched.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 * @param activityClass The activity to test.
49 */
50 public ActivityInstrumentationTestCase(String pkg, Class<T> activityClass) {
51 this(pkg, activityClass, false);
52 }
53
54 /**
Andy Stadler72d5de72009-04-21 11:54:14 -070055 * <b>NOTE:</b> The parameter <i>pkg</i> must refer to the package identifier of the
56 * package hosting the activity to be launched, which is specified in the AndroidManifest.xml
57 * file. This is not necessarily the same as the java package name.
58 *
59 * @param pkg The package hosting the activity to be launched.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 * @param activityClass The activity to test.
61 * @param initialTouchMode true = in touch mode
62 */
63 public ActivityInstrumentationTestCase(String pkg, Class<T> activityClass,
64 boolean initialTouchMode) {
65 mPackage = pkg;
66 mActivityClass = activityClass;
67 mInitialTouchMode = initialTouchMode;
68 }
69
70 @Override
71 public T getActivity() {
72 return (T) super.getActivity();
73 }
74
75 @Override
76 protected void setUp() throws Exception {
77 super.setUp();
78 // set initial touch mode
79 getInstrumentation().setInTouchMode(mInitialTouchMode);
80 setActivity(launchActivity(mPackage, mActivityClass, null));
81 }
82
83 @Override
84 protected void tearDown() throws Exception {
85 getActivity().finish();
86 setActivity(null);
87
88 // Scrub out members - protects against memory leaks in the case where someone
89 // creates a non-static inner class (thus referencing the test case) and gives it to
90 // someone else to hold onto
91 scrubClass(ActivityInstrumentationTestCase.class);
92
93 super.tearDown();
94 }
95
96 public void testActivityTestCaseSetUpProperly() throws Exception {
97 assertNotNull("activity should be launched successfully", getActivity());
98 }
99}