Rahul Ravikumar | 0533600 | 2019-10-14 15:04:32 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.test; |
| 18 | |
| 19 | import android.app.Instrumentation; |
| 20 | |
| 21 | import junit.framework.TestSuite; |
| 22 | import junit.framework.Test; |
| 23 | import 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 | * |
| 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>. |
| 33 | */ |
| 34 | @Deprecated |
| 35 | public 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) { |
| 74 | ((InstrumentationTestCase) test).injectInstrumentation(mInstrumentation); |
| 75 | } |
| 76 | |
| 77 | // run the test as usual |
| 78 | super.runTest(test, result); |
| 79 | } |
| 80 | } |