InstrumentationTest

public class InstrumentationTest
extends Object implements IDeviceTest, IResumableTest, ITestCollector, IAbiReceiver

java.lang.Object
   ↳ com.android.tradefed.testtype.InstrumentationTest


A Test that runs an instrumentation test package on given device.

Summary

Nested classes

class InstrumentationTest.FailedTestLogcatGenerator

A ResultForwarder that will forward a logcat snapshot on each failed test. 

class InstrumentationTest.FailedTestScreenshotGenerator

A ResultForwarder that will forward a screenshot on test failures. 

Constants

long TEST_COLLECTION_TIMEOUT_MS

default timeout for tests collection

String TEST_TIMEOUT_INST_ARGS_KEY

instrumentation test runner argument key used for individual test timeout

Fields

protected boolean mDebug

Public constructors

InstrumentationTest()

Public methods

void addDeviceListener(List<String> extraListeners)

Allows to add more custom listeners to the runner

void addInstrumentationArg(String key, String value)

Add an argument to provide when running the instrumentation tests.

IAbi getAbi()
String getCoverageTarget()

Get the coverageTarget previously set via setCoverageTarget(String).

boolean getDebug()

Get the instrumentation debug setting.

ITestDevice getDevice()

Get the device under test.

String getForceAbi()
long getMaxTimeout()

Returns the max timeout set for the instrumentation.

String getPackageName()

Get the Android manifest package to run.

String getRunName()

Get the custom test run name that will be provided to listener

String getRunnerName()

Gets the Android instrumentation runner to be used.

boolean isResumable()

void run(ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

void setAbi(IAbi abi)
void setBugreportFrequency(BugreportCollector.Freq freq)

Set the frequency with which to automatically collect bugreports after test failures.

void setClassName(String testClassName)

Optionally, set the test class name to run.

void setCollectTestsOnly(boolean shouldCollectTest)

Enables or disables test collection mode

void setCollectsTestsShellTimeout(int timeout)

This method is deprecated. This method is a no-op

void setCoverageTarget(String coverageTarget)

Set the coverage target of this test.

void setDebug(boolean debug)

Set the instrumentation debug setting.

void setDevice(ITestDevice device)

Inject the device under test.

void setEnforceFormat(boolean enforce)

Set True if we enforce the AJUR output format of instrumentation.

void setFallbackToSerialRerun(boolean reRunSerially)

Sets the --fallback-to-serial-rerun option.

void setForceAbi(String abi)

Sets force-abi option.

void setInstallFile(File installFile)

Set the optional file to install that contains the tests.

void setLogcatOnFailure(boolean logcatOnFailure)

Sets the --logcat-on-failure option.

void setLogcatOnFailureSize(int logcatOnFailureSize)

Sets the --logcat-on-failure-size option.

void setMethodName(String testMethodName)

Optionally, set the test method to run.

void setPackageName(String packageName)

Set the Android manifest package to run.

void setReRunUsingTestFile(boolean reRunUsingTestFile)

Sets the --rerun-from-file option.

void setRebootBeforeReRun(boolean rebootBeforeReRun)

Sets the --reboot-before-rerun option.

void setRerunMode(boolean rerun)

Optionally, set the rerun mode.

void setResumeMode(boolean resume)

Optionally, set the resume mode.

void setRunName(String runName)

Set the custom test run name that will be provided to listener

void setRunnerName(String runnerName)

Optionally, set the Android instrumentation runner to use.

void setScreenshotOnFailure(boolean screenshotOnFailure)

Sets the --screenshot-on-failure option.

void setShellTimeout(long timeout)

Optionally, set the maximum time (in milliseconds) expecting shell output from the device.

void setTestFilePathOnDevice(String testFilePathOnDevice)

Optionally, set the path to a file located on the device that should contain a list of line separated test classes and methods (format: com.foo.Class#method) to be run.

void setTestPackageName(String testPackageName)

Sets the test package filter.

void setTestSize(String size)

Optionally, set the test size to run.

void setTestTimeout(long timeout)

Optionally, set the maximum time (in milliseconds) for each individual test run.

void setTestsToRun(Collection<TestDescription> tests)

Set the collection of tests that should be executed by this InstrumentationTest.

Protected methods

ListInstrumentationParser getListInstrumentationParser()

Get the ListInstrumentationParser used to parse 'pm list instrumentation' queries.

String queryRunnerName()

Query the device for a test runner to use.

void setRunnerArgs(IRemoteAndroidTestRunner runner)

Constants

TEST_COLLECTION_TIMEOUT_MS

static final long TEST_COLLECTION_TIMEOUT_MS

default timeout for tests collection

Constant Value: 120000 (0x000000000001d4c0)

TEST_TIMEOUT_INST_ARGS_KEY

static final String TEST_TIMEOUT_INST_ARGS_KEY

instrumentation test runner argument key used for individual test timeout

Constant Value: "timeout_msec"

Fields

mDebug

protected boolean mDebug

Public constructors

InstrumentationTest

public InstrumentationTest ()

Public methods

addDeviceListener

public void addDeviceListener (List<String> extraListeners)

Allows to add more custom listeners to the runner

Parameters
extraListeners List

addInstrumentationArg

public void addInstrumentationArg (String key, 
                String value)

Add an argument to provide when running the instrumentation tests.

Parameters
key String: the argument name

value String: the argument value

getAbi

public IAbi getAbi ()

Returns
IAbi

getCoverageTarget

public String getCoverageTarget ()

Get the coverageTarget previously set via setCoverageTarget(String).

Returns
String

getDebug

public boolean getDebug ()

Get the instrumentation debug setting.

Returns
boolean The boolean debug setting.

getDevice

public ITestDevice getDevice ()

Get the device under test.

Returns
ITestDevice the ITestDevice

getForceAbi

public String getForceAbi ()

Returns
String

getMaxTimeout

public long getMaxTimeout ()

Returns the max timeout set for the instrumentation.

Returns
long

getPackageName

public String getPackageName ()

Get the Android manifest package to run.

Returns
String

getRunName

public String getRunName ()

Get the custom test run name that will be provided to listener

Returns
String

getRunnerName

public String getRunnerName ()

Gets the Android instrumentation runner to be used.

Returns
String

isResumable

public boolean isResumable ()

Returns
boolean

run

public void run (ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

Parameters
listener ITestInvocationListener: the ITestInvocationListener of test results

Throws
DeviceNotAvailableException

setAbi

public void setAbi (IAbi abi)

Parameters
abi IAbi

setBugreportFrequency

public void setBugreportFrequency (BugreportCollector.Freq freq)

Set the frequency with which to automatically collect bugreports after test failures.

Note that there is _no feedback mechanism_ between the test runner and the bugreport collector, so use the EACH setting with due caution: if a large quantity of failures happen in rapid succession, the bugreport for a given one of the failures could end up being collected tens of minutes or hours after the respective failure occurred.

Parameters
freq BugreportCollector.Freq

setClassName

public void setClassName (String testClassName)

Optionally, set the test class name to run.

Parameters
testClassName String

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

setCollectsTestsShellTimeout

public void setCollectsTestsShellTimeout (int timeout)

This method is deprecated.
This method is a no-op

Set the max time in ms to allow for the 'max time to shell output response' when collecting tests.

Parameters
timeout int

setCoverageTarget

public void setCoverageTarget (String coverageTarget)

Set the coverage target of this test.

Currently unused. This method is just present so coverageTarget can be later retrieved via getCoverageTarget()

Parameters
coverageTarget String

setDebug

public void setDebug (boolean debug)

Set the instrumentation debug setting.

Parameters
debug boolean: boolean value to set the instrumentation debug setting to.

setDevice

public void setDevice (ITestDevice device)

Inject the device under test.

Parameters
device ITestDevice: the ITestDevice to use

setEnforceFormat

public void setEnforceFormat (boolean enforce)

Set True if we enforce the AJUR output format of instrumentation.

Parameters
enforce boolean

setFallbackToSerialRerun

public void setFallbackToSerialRerun (boolean reRunSerially)

Sets the --fallback-to-serial-rerun option.

Parameters
reRunSerially boolean

setForceAbi

public void setForceAbi (String abi)

Sets force-abi option.

setInstallFile

public void setInstallFile (File installFile)

Set the optional file to install that contains the tests.

Parameters
installFile File: the installable File

setLogcatOnFailure

public void setLogcatOnFailure (boolean logcatOnFailure)

Sets the --logcat-on-failure option.

Parameters
logcatOnFailure boolean

setLogcatOnFailureSize

public void setLogcatOnFailureSize (int logcatOnFailureSize)

Sets the --logcat-on-failure-size option.

Parameters
logcatOnFailureSize int

setMethodName

public void setMethodName (String testMethodName)

Optionally, set the test method to run.

Parameters
testMethodName String

setPackageName

public void setPackageName (String packageName)

Set the Android manifest package to run.

Parameters
packageName String

setReRunUsingTestFile

public void setReRunUsingTestFile (boolean reRunUsingTestFile)

Sets the --rerun-from-file option.

Parameters
reRunUsingTestFile boolean

setRebootBeforeReRun

public void setRebootBeforeReRun (boolean rebootBeforeReRun)

Sets the --reboot-before-rerun option.

Parameters
rebootBeforeReRun boolean

setRerunMode

public void setRerunMode (boolean rerun)

Optionally, set the rerun mode.

Parameters
rerun boolean

setResumeMode

public void setResumeMode (boolean resume)

Optionally, set the resume mode.

Parameters
resume boolean

setRunName

public void setRunName (String runName)

Set the custom test run name that will be provided to listener

Parameters
runName String

setRunnerName

public void setRunnerName (String runnerName)

Optionally, set the Android instrumentation runner to use.

Parameters
runnerName String

setScreenshotOnFailure

public void setScreenshotOnFailure (boolean screenshotOnFailure)

Sets the --screenshot-on-failure option.

Parameters
screenshotOnFailure boolean

setShellTimeout

public void setShellTimeout (long timeout)

Optionally, set the maximum time (in milliseconds) expecting shell output from the device.

Parameters
timeout long

setTestFilePathOnDevice

public void setTestFilePathOnDevice (String testFilePathOnDevice)

Optionally, set the path to a file located on the device that should contain a list of line separated test classes and methods (format: com.foo.Class#method) to be run. If set, will automatically attempt to re-run tests using this test file via InstrumentationFileTest instead of executing separate adb commands for each remaining test via InstrumentationSerialTest"

Parameters
testFilePathOnDevice String

setTestPackageName

public void setTestPackageName (String testPackageName)

Sets the test package filter.

If non-null, only tests within the given java package will be executed.

Will be ignored if a non-null value has been provided to setClassName(String)

Parameters
testPackageName String

setTestSize

public void setTestSize (String size)

Optionally, set the test size to run.

Parameters
size String

setTestTimeout

public void setTestTimeout (long timeout)

Optionally, set the maximum time (in milliseconds) for each individual test run.

Parameters
timeout long

setTestsToRun

public void setTestsToRun (Collection<TestDescription> tests)

Set the collection of tests that should be executed by this InstrumentationTest.

Parameters
tests Collection: the tests to run

Protected methods

getListInstrumentationParser

protected ListInstrumentationParser getListInstrumentationParser ()

Get the ListInstrumentationParser used to parse 'pm list instrumentation' queries.

Returns
ListInstrumentationParser

queryRunnerName

protected String queryRunnerName ()

Query the device for a test runner to use.

Returns
String the first test runner name that matches the package or null if we don't find any.

Throws
DeviceNotAvailableException

setRunnerArgs

protected void setRunnerArgs (IRemoteAndroidTestRunner runner)

Parameters
runner IRemoteAndroidTestRunner