1 /* 2 * Copyright (C) 2013 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 androidx.test.uiautomator; 18 19 import android.test.AndroidTestRunner; 20 import android.test.InstrumentationTestRunner; 21 22 import junit.framework.AssertionFailedError; 23 import junit.framework.Test; 24 import junit.framework.TestListener; 25 26 /** 27 * Test runner for {@link UiAutomatorTestCase}s. Such tests are executed 28 * on the device and have access to an applications context. 29 * 30 * @deprecated as it only handles deprecated {@link UiAutomatorTestCase}s. You should use 31 * {@link UiDevice#getInstance(android.app.Instrumentation)} from any test class as long as you 32 * have access to an {@link android.app.Instrumentation} instance. 33 */ 34 @Deprecated 35 public class UiAutomatorInstrumentationTestRunner extends InstrumentationTestRunner { 36 37 /** 38 * Perform initialization specific to UiAutomator test. It sets up the test case so that 39 * it can access the UiDevice and gives it access to the command line arguments. 40 * @param test UiAutomatorTestCase to initialize. 41 */ initializeUiAutomatorTest(UiAutomatorTestCase test)42 protected void initializeUiAutomatorTest(UiAutomatorTestCase test) { 43 test.initialize(getArguments()); 44 } 45 46 @Override getAndroidTestRunner()47 protected AndroidTestRunner getAndroidTestRunner() { 48 AndroidTestRunner testRunner = super.getAndroidTestRunner(); 49 testRunner.addTestListener(new TestListener() { 50 @Override 51 public void startTest(Test test) { 52 if (test instanceof UiAutomatorTestCase) { 53 initializeUiAutomatorTest((UiAutomatorTestCase)test); 54 } 55 } 56 57 @Override 58 public void endTest(Test test) { 59 } 60 61 @Override 62 public void addFailure(Test test, AssertionFailedError e) { 63 } 64 65 @Override 66 public void addError(Test test, Throwable t) { 67 } 68 }); 69 return testRunner; 70 } 71 } 72