Fields Summary |
---|
private final String | mPackageName |
private final String | mRunnerName |
private com.android.ddmlib.IDevice | mRemoteDevice |
private Map | mArgMapmap of name-value instrumentation argument pairs |
private InstrumentationResultParser | mParser |
private static final String | LOG_TAG |
private static final String | DEFAULT_RUNNER_NAME |
private static final char | CLASS_SEPARATOR |
private static final char | METHOD_SEPARATOR |
private static final char | RUNNER_SEPARATOR |
private static final String | CLASS_ARG_NAME |
private static final String | LOG_ARG_NAME |
private static final String | DEBUG_ARG_NAME |
private static final String | COVERAGE_ARG_NAME |
private static final String | PACKAGE_ARG_NAME |
Methods Summary |
---|
public void | addBooleanArg(java.lang.String name, boolean value)Adds a boolean argument to include in instrumentation command.
addInstrumentationArg(name, Boolean.toString(value));
|
public void | addInstrumentationArg(java.lang.String name, java.lang.String value)Adds a argument to include in instrumentation command.
Must be called before 'run'. If an argument with given name has already been provided, it's
value will be overridden.
if (name == null || value == null) {
throw new IllegalArgumentException("name or value arguments cannot be null");
}
mArgMap.put(name, value);
|
public void | cancel()Requests cancellation of this test run.
if (mParser != null) {
mParser.cancel();
}
|
private java.lang.String | getArgsCommand()Returns the full instrumentation command line syntax for the provided instrumentation
arguments.
Returns an empty string if no arguments were specified.
StringBuilder commandBuilder = new StringBuilder();
for (Entry<String, String> argPair : mArgMap.entrySet()) {
final String argCmd = String.format(" -e %s %s", argPair.getKey(),
argPair.getValue());
commandBuilder.append(argCmd);
}
return commandBuilder.toString();
|
public java.lang.String | getPackageName()Returns the application package name.
return mPackageName;
|
public java.lang.String | getRunnerName()Returns the runnerName.
if (mRunnerName == null) {
return DEFAULT_RUNNER_NAME;
}
return mRunnerName;
|
private java.lang.String | getRunnerPath()Returns the complete instrumentation component path.
return getPackageName() + RUNNER_SEPARATOR + getRunnerName();
|
public void | run(ITestRunListener listener)Execute this test run.
final String runCaseCommandStr = String.format("am instrument -w -r %s %s",
getArgsCommand(), getRunnerPath());
Log.d(LOG_TAG, runCaseCommandStr);
mParser = new InstrumentationResultParser(listener);
try {
mRemoteDevice.executeShellCommand(runCaseCommandStr, mParser);
} catch (IOException e) {
Log.e(LOG_TAG, e);
listener.testRunFailed(e.toString());
}
|
public void | setClassName(java.lang.String className)Sets to run only tests in this class
Must be called before 'run'.
addInstrumentationArg(CLASS_ARG_NAME, className);
|
public void | setClassNames(java.lang.String[] classNames)Sets to run only tests in the provided classes
Must be called before 'run'.
If providing more than one class, requires a InstrumentationTestRunner that supports
the multiple class argument syntax.
StringBuilder classArgBuilder = new StringBuilder();
for (int i = 0; i < classNames.length; i++) {
if (i != 0) {
classArgBuilder.append(CLASS_SEPARATOR);
}
classArgBuilder.append(classNames[i]);
}
setClassName(classArgBuilder.toString());
|
public void | setCoverage(boolean coverage)Sets this code coverage mode of this test run.
addBooleanArg(COVERAGE_ARG_NAME, coverage);
|
public void | setDebug(boolean debug)Sets this debug mode of this test run. If true, the Android test runner will wait for a
debugger to attach before proceeding with test execution.
addBooleanArg(DEBUG_ARG_NAME, debug);
|
public void | setLogOnly(boolean logOnly)Sets this test run to log only mode - skips test execution.
addBooleanArg(LOG_ARG_NAME, logOnly);
|
public void | setMethodName(java.lang.String className, java.lang.String testName)Sets to run only specified test method
Must be called before 'run'.
setClassName(className + METHOD_SEPARATOR + testName);
|
public void | setTestPackageName(java.lang.String packageName)Sets to run all tests in specified package
Must be called before 'run'.
addInstrumentationArg(PACKAGE_ARG_NAME, packageName);
|