• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.TestCase;
22 
23 /**
24  * Helper JUnit test case that stores reference to an Android device and test data.
25  *
26  * Can be extended to verify an Android device's response to various adb commands.
27  */
28 public abstract class DeviceTestCase extends TestCase implements DeviceTest {
29 
30     /** Android device under test */
31     private IDevice mDevice = null;
32     /** optionally, used to store path to test data files */
33     private String mTestDataPath = null;
34 
DeviceTestCase()35     protected DeviceTestCase() {
36     }
37 
38     /**
39      * {@inheritDoc}
40      */
setDevice(IDevice device)41     public void setDevice(IDevice device) {
42         mDevice = device;
43     }
44 
45     /**
46      * {@inheritDoc}
47      */
getDevice()48     public IDevice getDevice() {
49         return mDevice;
50     }
51 
52     /**
53      * {@inheritDoc}
54      */
getTestAppPath()55     public String getTestAppPath() {
56         return mTestDataPath;
57     }
58 
59     /**
60      * {@inheritDoc}
61      */
setTestAppPath(String path)62     public void setTestAppPath(String path) {
63         mTestDataPath = path;
64     }
65 
66     @Override
setUp()67     protected void setUp() throws Exception {
68         // ensure device has been set before test is run
69         assertNotNull(getDevice());
70     }
71 }
72