2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.ddmlib.testrunner;
19 import com.android.ddmlib.IDevice;
20 import com.android.ddmlib.AdbCommandRejectedException;
21 import com.android.ddmlib.ShellCommandUnresponsiveException;
22 import com.android.ddmlib.TimeoutException;
24 import java.io.IOException;
25 import java.util.Collection;
28 * Interface for running a Android test command remotely and reporting result to a listener.
30 public interface IRemoteAndroidTestRunner {
32 public static enum TestSize {
33 /** Run tests annotated with SmallTest */
35 /** Run tests annotated with MediumTest */
37 /** Run tests annotated with LargeTest */
40 private String mRunnerValue;
43 * Create a {@link TestSize}.
45 * @param runnerValue the {@link String} value that represents the size that is passed to
46 * device. Defined on device in android.test.InstrumentationTestRunner.
48 TestSize(String runnerValue) {
49 mRunnerValue = runnerValue;
52 String getRunnerValue() {
57 * Return the {@link TestSize} corresponding to the given Android platform defined value.
59 * @throws IllegalArgumentException if {@link TestSize} cannot be found.
61 public static TestSize getTestSize(String value) {
62 // build the error message in the success case too, to avoid two for loops
63 StringBuilder msgBuilder = new StringBuilder("Unknown TestSize ");
64 msgBuilder.append(value);
65 msgBuilder.append(", Must be one of ");
66 for (TestSize size : values()) {
67 if (size.getRunnerValue().equals(value)) {
70 msgBuilder.append(size.getRunnerValue());
71 msgBuilder.append(", ");
73 throw new IllegalArgumentException(msgBuilder.toString());
78 * Returns the application package name.
80 public String getPackageName();
83 * Returns the runnerName.
85 public String getRunnerName();
88 * Sets to run only tests in this class
89 * Must be called before 'run'.
91 * @param className fully qualified class name (eg x.y.z)
93 public void setClassName(String className);
96 * Sets to run only tests in the provided classes
97 * Must be called before 'run'.
99 * If providing more than one class, requires a InstrumentationTestRunner that supports
100 * the multiple class argument syntax.
102 * @param classNames array of fully qualified class names (eg x.y.z)
104 public void setClassNames(String[] classNames);
107 * Sets to run only specified test method
108 * Must be called before 'run'.
110 * @param className fully qualified class name (eg x.y.z)
111 * @param testName method name
113 public void setMethodName(String className, String testName);
116 * Sets to run all tests in specified package
117 * Must be called before 'run'.
119 * @param packageName fully qualified package name (eg x.y.z)
121 public void setTestPackageName(String packageName);
124 * Sets to run only tests of given size.
125 * Must be called before 'run'.
127 * @param size the {@link TestSize} to run.
129 public void setTestSize(TestSize size);
132 * Adds a argument to include in instrumentation command.
134 * Must be called before 'run'. If an argument with given name has already been provided, it's
135 * value will be overridden.
137 * @param name the name of the instrumentation bundle argument
138 * @param value the value of the argument
140 public void addInstrumentationArg(String name, String value);
143 * Removes a previously added argument.
145 * @param name the name of the instrumentation bundle argument to remove
147 public void removeInstrumentationArg(String name);
150 * Adds a boolean argument to include in instrumentation command.
152 * @see RemoteAndroidTestRunner#addInstrumentationArg
154 * @param name the name of the instrumentation bundle argument
155 * @param value the value of the argument
157 public void addBooleanArg(String name, boolean value);
160 * Sets this test run to log only mode - skips test execution.
162 public void setLogOnly(boolean logOnly);
165 * Sets this debug mode of this test run. If true, the Android test runner will wait for a
166 * debugger to attach before proceeding with test execution.
168 public void setDebug(boolean debug);
171 * Sets this code coverage mode of this test run.
173 public void setCoverage(boolean coverage);
176 * Sets the maximum time allowed between output of the shell command running the tests on
179 * This allows setting a timeout in case the tests can become stuck and never finish. This is
180 * different from the normal timeout on the connection.
182 * By default no timeout will be specified.
184 * @see {@link IDevice#executeShellCommand(String, com.android.ddmlib.IShellOutputReceiver, int)}
186 public void setMaxtimeToOutputResponse(int maxTimeToOutputResponse);
189 * Execute this test run.
191 * Convenience method for {@link #run(Collection)}.
193 * @param listeners listens for test results
194 * @throws TimeoutException in case of a timeout on the connection.
195 * @throws AdbCommandRejectedException if adb rejects the command
196 * @throws ShellCommandUnresponsiveException if the device did not output any test result for
197 * a period longer than the max time to output.
198 * @throws IOException if connection to device was lost.
200 * @see #setMaxtimeToOutputResponse(int)
202 public void run(ITestRunListener... listeners)
203 throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
207 * Execute this test run.
209 * @param listeners collection of listeners for test results
210 * @throws TimeoutException in case of a timeout on the connection.
211 * @throws AdbCommandRejectedException if adb rejects the command
212 * @throws ShellCommandUnresponsiveException if the device did not output any test result for
213 * a period longer than the max time to output.
214 * @throws IOException if connection to device was lost.
216 * @see #setMaxtimeToOutputResponse(int)
218 public void run(Collection<ITestRunListener> listeners)
219 throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
223 * Requests cancellation of this test run.
225 public void cancel();