1 /* 2 * Copyright (C) 2009 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 com.android.hosttest; 18 19 import com.android.ddmlib.IDevice; 20 21 import junit.framework.Test; 22 import junit.framework.TestResult; 23 import junit.framework.TestSuite; 24 25 /** 26 * Helper JUnit test suite that stores reference to an Android device and test data. 27 */ 28 public class DeviceTestSuite extends TestSuite implements DeviceTest { 29 30 private IDevice mDevice = null; 31 private String mTestDataPath = null; 32 DeviceTestSuite(Class testClass)33 public DeviceTestSuite(Class testClass) { 34 super(testClass); 35 } 36 DeviceTestSuite()37 public DeviceTestSuite() { 38 super(); 39 } 40 41 /** 42 * Adds the tests from the given class to the suite 43 */ 44 @Override addTestSuite(Class testClass)45 public void addTestSuite(Class testClass) { 46 addTest(new DeviceTestSuite(testClass)); 47 } 48 49 /** 50 * Overrides parent method to pass in device and test app path to included test 51 */ 52 @Override runTest(Test test, TestResult result)53 public void runTest(Test test, TestResult result) { 54 if (test instanceof DeviceTest) { 55 DeviceTest deviceTest = (DeviceTest)test; 56 deviceTest.setDevice(mDevice); 57 deviceTest.setTestAppPath(mTestDataPath); 58 } 59 test.run(result); 60 } 61 62 /** 63 * {@inheritDoc} 64 */ getDevice()65 public IDevice getDevice() { 66 return mDevice; 67 } 68 69 /** 70 * {@inheritDoc} 71 */ getTestAppPath()72 public String getTestAppPath() { 73 return mTestDataPath; 74 } 75 76 /** 77 * {@inheritDoc} 78 */ setDevice(IDevice device)79 public void setDevice(IDevice device) { 80 mDevice = device; 81 } 82 83 /** 84 * {@inheritDoc} 85 */ setTestAppPath(String path)86 public void setTestAppPath(String path) { 87 mTestDataPath = path; 88 } 89 } 90