blob: a53fa267f1e14af5d6d351cd2084e1536a835812 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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.Instrumentation;
20
21import junit.framework.TestSuite;
22import junit.framework.Test;
23import junit.framework.TestResult;
24
25/**
26 * A {@link junit.framework.TestSuite} that injects {@link android.app.Instrumentation} into
27 * {@link InstrumentationTestCase} before running them.
Stephan Linznerb51617f2016-01-27 18:09:50 -080028 *
29 * @deprecated Use
30 * <a href="{@docRoot}reference/android/support/test/InstrumentationRegistry.html">
31 * InstrumentationRegistry</a> instead. New tests should be written using the
32 * <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a>.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 */
Stephan Linznerb51617f2016-01-27 18:09:50 -080034@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035public class InstrumentationTestSuite extends TestSuite {
36
37 private final Instrumentation mInstrumentation;
38
39 /**
40 * @param instr The instrumentation that will be injected into each
41 * test before running it.
42 */
43 public InstrumentationTestSuite(Instrumentation instr) {
44 mInstrumentation = instr;
45 }
46
47
48 public InstrumentationTestSuite(String name, Instrumentation instr) {
49 super(name);
50 mInstrumentation = instr;
51 }
52
53 /**
54 * @param theClass Inspected for methods starting with 'test'
55 * @param instr The instrumentation to inject into each test before
56 * running.
57 */
58 public InstrumentationTestSuite(final Class theClass, Instrumentation instr) {
59 super(theClass);
60 mInstrumentation = instr;
61 }
62
63
64 @Override
65 public void addTestSuite(Class testClass) {
66 addTest(new InstrumentationTestSuite(testClass, mInstrumentation));
67 }
68
69
70 @Override
71 public void runTest(Test test, TestResult result) {
72
73 if (test instanceof InstrumentationTestCase) {
Jack Wang7aba54b2009-08-20 19:20:54 -070074 ((InstrumentationTestCase) test).injectInstrumentation(mInstrumentation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 }
76
77 // run the test as usual
78 super.runTest(test, result);
79 }
80}