• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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 package com.android.test.runner.junit3;
17 
18 import android.app.Instrumentation;
19 import android.content.Context;
20 import android.test.AndroidTestCase;
21 import android.test.InstrumentationTestCase;
22 
23 import junit.framework.Test;
24 import junit.framework.TestResult;
25 import junit.framework.TestSuite;
26 
27 import org.junit.Ignore;
28 
29 /**
30  * A {@link TestSuite} used to pass {@link Context} and {@link Instrumentation} references to child
31  * tests.
32  */
33 @Ignore
34 class AndroidTestSuite extends TestSuite {
35 
36     private final Instrumentation mInstr;
37 
AndroidTestSuite(Class<?> clazz, Instrumentation instrumentation)38     AndroidTestSuite(Class<?> clazz, Instrumentation instrumentation) {
39         super(clazz);
40         mInstr = instrumentation;
41     }
42 
AndroidTestSuite(String name, Instrumentation instrumentation)43     AndroidTestSuite(String name, Instrumentation instrumentation) {
44         super(name);
45         mInstr = instrumentation;
46     }
47 
48     @Override
runTest(Test test, TestResult result)49     public void runTest(Test test, TestResult result) {
50         if (test instanceof AndroidTestCase) {
51             ((AndroidTestCase)test).setContext(mInstr.getTargetContext());
52         }
53         if (test instanceof InstrumentationTestCase) {
54             ((InstrumentationTestCase)test).injectInstrumentation(mInstr);
55         }
56         super.runTest(test, result);
57     }
58 
getInstrumentation()59     Instrumentation getInstrumentation() {
60         return mInstr;
61     }
62 }
63