blob: 7a78ffbb226d4f8a40817a236a39b65d0d7d7284 [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.
28 */
29public class InstrumentationTestSuite extends TestSuite {
30
31 private final Instrumentation mInstrumentation;
32
33 /**
34 * @param instr The instrumentation that will be injected into each
35 * test before running it.
36 */
37 public InstrumentationTestSuite(Instrumentation instr) {
38 mInstrumentation = instr;
39 }
40
41
42 public InstrumentationTestSuite(String name, Instrumentation instr) {
43 super(name);
44 mInstrumentation = instr;
45 }
46
47 /**
48 * @param theClass Inspected for methods starting with 'test'
49 * @param instr The instrumentation to inject into each test before
50 * running.
51 */
52 public InstrumentationTestSuite(final Class theClass, Instrumentation instr) {
53 super(theClass);
54 mInstrumentation = instr;
55 }
56
57
58 @Override
59 public void addTestSuite(Class testClass) {
60 addTest(new InstrumentationTestSuite(testClass, mInstrumentation));
61 }
62
63
64 @Override
65 public void runTest(Test test, TestResult result) {
66
67 if (test instanceof InstrumentationTestCase) {
Jack Wang7aba54b2009-08-20 19:20:54 -070068 ((InstrumentationTestCase) test).injectInstrumentation(mInstrumentation);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 }
70
71 // run the test as usual
72 super.runTest(test, result);
73 }
74}