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.TimeoutException;
22 import java.io.IOException;
23 import java.util.Collection;
26 * Interface for running a Android test command remotely and reporting result to a listener.
28 public interface IRemoteAndroidTestRunner {
30 public static enum TestSize {
31 /** Run tests annotated with SmallTest */
33 /** Run tests annotated with MediumTest */
35 /** Run tests annotated with LargeTest */
38 private String mRunnerValue;
41 * Create a {@link TestSize}.
43 * @param runnerValue the {@link String} value that represents the size that is passed to
44 * device. Defined on device in android.test.InstrumentationTestRunner.
46 TestSize(String runnerValue) {
47 mRunnerValue = runnerValue;
50 String getRunnerValue() {
55 * Return the {@link TestSize} corresponding to the given Android platform defined value.
57 * @throws IllegalArgumentException if {@link TestSize} cannot be found.
59 public static TestSize getTestSize(String value) {
60 // build the error message in the success case too, to avoid two for loops
61 StringBuilder msgBuilder = new StringBuilder("Unknown TestSize ");
62 msgBuilder.append(value);
63 msgBuilder.append(", Must be one of ");
64 for (TestSize size : values()) {
65 if (size.getRunnerValue().equals(value)) {
68 msgBuilder.append(size.getRunnerValue());
69 msgBuilder.append(", ");
71 throw new IllegalArgumentException(msgBuilder.toString());
76 * Returns the application package name.
78 public String getPackageName();
81 * Returns the runnerName.
83 public String getRunnerName();
86 * Sets to run only tests in this class
87 * Must be called before 'run'.
89 * @param className fully qualified class name (eg x.y.z)
91 public void setClassName(String className);
94 * Sets to run only tests in the provided classes
95 * Must be called before 'run'.
97 * If providing more than one class, requires a InstrumentationTestRunner that supports
98 * the multiple class argument syntax.
100 * @param classNames array of fully qualified class names (eg x.y.z)
102 public void setClassNames(String[] classNames);
105 * Sets to run only specified test method
106 * Must be called before 'run'.
108 * @param className fully qualified class name (eg x.y.z)
109 * @param testName method name
111 public void setMethodName(String className, String testName);
114 * Sets to run all tests in specified package
115 * Must be called before 'run'.
117 * @param packageName fully qualified package name (eg x.y.z)
119 public void setTestPackageName(String packageName);
122 * Sets to run only tests of given size.
123 * Must be called before 'run'.
125 * @param size the {@link TestSize} to run.
127 public void setTestSize(TestSize size);
130 * Adds a argument to include in instrumentation command.
132 * Must be called before 'run'. If an argument with given name has already been provided, it's
133 * value will be overridden.
135 * @param name the name of the instrumentation bundle argument
136 * @param value the value of the argument
138 public void addInstrumentationArg(String name, String value);
141 * Removes a previously added argument.
143 * @param name the name of the instrumentation bundle argument to remove
145 public void removeInstrumentationArg(String name);
148 * Adds a boolean argument to include in instrumentation command.
150 * @see RemoteAndroidTestRunner#addInstrumentationArg
152 * @param name the name of the instrumentation bundle argument
153 * @param value the value of the argument
155 public void addBooleanArg(String name, boolean value);
158 * Sets this test run to log only mode - skips test execution.
160 public void setLogOnly(boolean logOnly);
163 * Sets this debug mode of this test run. If true, the Android test runner will wait for a
164 * debugger to attach before proceeding with test execution.
166 public void setDebug(boolean debug);
169 * Sets this code coverage mode of this test run.
171 public void setCoverage(boolean coverage);
174 * Sets the timeout to use for the adb shell command issued.
176 * By default no timeout will be specified.
178 * @see {@link IDevice#executeShellCommand(String, com.android.ddmlib.IShellOutputReceiver, int)}
180 public void setTimeout(int timeout);
183 * Execute this test run.
185 * Convenience method for {@link #run(Collection)}.
187 * @param listeners listens for test results
188 * @throws TimeoutException in case of a timeout on the connection.
189 * @throws IOException if connection to device was lost.
191 public void run(ITestRunListener... listeners) throws TimeoutException, IOException;
194 * Execute this test run.
196 * @param listeners collection of listeners for test results
197 * @throws TimeoutException in case of a timeout on the connection.
198 * @throws IOException if connection to device was lost.
200 public void run(Collection<ITestRunListener> listeners) throws TimeoutException, IOException;
203 * Requests cancellation of this test run.
205 public void cancel();