blob: e5a9991ae557140a31114f641605bfe524108330 [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 /**
43 * @param pkg The package of the instrumentation.
44 * @param activityClass The activity to test.
45 */
46 public ActivityInstrumentationTestCase(String pkg, Class<T> activityClass) {
47 this(pkg, activityClass, false);
48 }
49
50 /**
51 * @param pkg The package of the instrumentation.
52 * @param activityClass The activity to test.
53 * @param initialTouchMode true = in touch mode
54 */
55 public ActivityInstrumentationTestCase(String pkg, Class<T> activityClass,
56 boolean initialTouchMode) {
57 mPackage = pkg;
58 mActivityClass = activityClass;
59 mInitialTouchMode = initialTouchMode;
60 }
61
62 @Override
63 public T getActivity() {
64 return (T) super.getActivity();
65 }
66
67 @Override
68 protected void setUp() throws Exception {
69 super.setUp();
70 // set initial touch mode
71 getInstrumentation().setInTouchMode(mInitialTouchMode);
72 setActivity(launchActivity(mPackage, mActivityClass, null));
73 }
74
75 @Override
76 protected void tearDown() throws Exception {
77 getActivity().finish();
78 setActivity(null);
79
80 // Scrub out members - protects against memory leaks in the case where someone
81 // creates a non-static inner class (thus referencing the test case) and gives it to
82 // someone else to hold onto
83 scrubClass(ActivityInstrumentationTestCase.class);
84
85 super.tearDown();
86 }
87
88 public void testActivityTestCaseSetUpProperly() throws Exception {
89 assertNotNull("activity should be launched successfully", getActivity());
90 }
91}