FileDocCategorySizeDatePackage
RemoteAndroidTestRunner.javaAPI DocAndroid 1.5 API8147Wed May 06 22:41:08 BST 2009com.android.ddmlib.testrunner

RemoteAndroidTestRunner

public class RemoteAndroidTestRunner extends Object
Runs a Android test command remotely and reports results.

Fields Summary
private final String
mPackageName
private final String
mRunnerName
private com.android.ddmlib.IDevice
mRemoteDevice
private Map
mArgMap
map 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
Constructors Summary
public RemoteAndroidTestRunner(String packageName, String runnerName, com.android.ddmlib.IDevice remoteDevice)
Creates a remote Android test runner.

param
packageName the Android application package that contains the tests to run
param
runnerName the instrumentation test runner to execute. If null, will use default runner
param
remoteDevice the Android device to execute tests on

 
                                                       
       
                                    
                                     
        
        mPackageName = packageName;
        mRunnerName = runnerName;
        mRemoteDevice = remoteDevice;
        mArgMap = new Hashtable<String, String>();
    
public RemoteAndroidTestRunner(String packageName, com.android.ddmlib.IDevice remoteDevice)
Alternate constructor. Uses default instrumentation runner.

param
packageName the Android application package that contains the tests to run
param
remoteDevice the Android device to execute tests on

        this(packageName, null, remoteDevice);
    
Methods Summary
public voidaddBooleanArg(java.lang.String name, boolean value)
Adds a boolean argument to include in instrumentation command.

see
RemoteAndroidTestRunner#addInstrumentationArg
param
name the name of the instrumentation bundle argument
param
value the value of the argument

        addInstrumentationArg(name, Boolean.toString(value));
    
public voidaddInstrumentationArg(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.

param
name the name of the instrumentation bundle argument
param
value the value of the argument

        if (name == null || value == null) {
            throw new IllegalArgumentException("name or value arguments cannot be null");
        }
        mArgMap.put(name, value);  
    
public voidcancel()
Requests cancellation of this test run.

        if (mParser != null) {
            mParser.cancel();
        }
    
private java.lang.StringgetArgsCommand()
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.StringgetPackageName()
Returns the application package name.

        return mPackageName;
    
public java.lang.StringgetRunnerName()
Returns the runnerName.

        if (mRunnerName == null) {
            return DEFAULT_RUNNER_NAME;
        }
        return mRunnerName;
    
private java.lang.StringgetRunnerPath()
Returns the complete instrumentation component path.

        return getPackageName() + RUNNER_SEPARATOR + getRunnerName();
    
public voidrun(ITestRunListener listener)
Execute this test run.

param
listener listens for test results

        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 voidsetClassName(java.lang.String className)
Sets to run only tests in this class Must be called before 'run'.

param
className fully qualified class name (eg x.y.z)

        addInstrumentationArg(CLASS_ARG_NAME, className);
    
public voidsetClassNames(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.

param
classNames array of fully qualified class names (eg x.y.z)

        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 voidsetCoverage(boolean coverage)
Sets this code coverage mode of this test run.

        addBooleanArg(COVERAGE_ARG_NAME, coverage);
    
public voidsetDebug(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 voidsetLogOnly(boolean logOnly)
Sets this test run to log only mode - skips test execution.

        addBooleanArg(LOG_ARG_NAME, logOnly);
    
public voidsetMethodName(java.lang.String className, java.lang.String testName)
Sets to run only specified test method Must be called before 'run'.

param
className fully qualified class name (eg x.y.z)
param
testName method name

        setClassName(className + METHOD_SEPARATOR + testName);
    
public voidsetTestPackageName(java.lang.String packageName)
Sets to run all tests in specified package Must be called before 'run'.

param
packageName fully qualified package name (eg x.y.z)

        addInstrumentationArg(PACKAGE_ARG_NAME, packageName);