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 junit.framework.Test; 19 import junit.framework.TestResult; 20 import junit.framework.TestSuite; 21 22 import org.junit.Ignore; 23 24 import android.app.Instrumentation; 25 import android.content.Context; 26 import android.os.Bundle; 27 import android.test.AndroidTestCase; 28 import android.test.InstrumentationTestCase; 29 30 import com.android.test.BundleTest; 31 32 /** 33 * A {@link TestSuite} used to pass {@link Context} and {@link Instrumentation} references to child 34 * tests. 35 */ 36 @Ignore 37 class AndroidTestSuite extends TestSuite { 38 39 private final Instrumentation mInstr; 40 private final Bundle mBundle; 41 AndroidTestSuite(Class<?> clazz, Bundle bundle, Instrumentation instrumentation)42 AndroidTestSuite(Class<?> clazz, Bundle bundle, Instrumentation instrumentation) { 43 super(clazz); 44 mBundle = bundle; 45 mInstr = instrumentation; 46 } 47 AndroidTestSuite(String name, Bundle bundle, Instrumentation instrumentation)48 AndroidTestSuite(String name, Bundle bundle, Instrumentation instrumentation) { 49 super(name); 50 mBundle = bundle; 51 mInstr = instrumentation; 52 } 53 54 @Override runTest(Test test, TestResult result)55 public void runTest(Test test, TestResult result) { 56 if (test instanceof AndroidTestCase) { 57 ((AndroidTestCase)test).setContext(mInstr.getTargetContext()); 58 } 59 if (test instanceof InstrumentationTestCase) { 60 ((InstrumentationTestCase)test).injectInstrumentation(mInstr); 61 } 62 if (test instanceof BundleTest) { 63 ((BundleTest)test).injectBundle(mBundle); 64 } 65 super.runTest(test, result); 66 } 67 getInstrumentation()68 Instrumentation getInstrumentation() { 69 return mInstr; 70 } 71 getBundle()72 Bundle getBundle() { 73 return mBundle; 74 } 75 } 76