InstrumentationTest

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

java.lang.Object
   ↳ com.android.tradefed.testtype.InstrumentationTest
Known Direct Subclasses
AndroidJUnitTest A Test that runs an instrumentation test package on given device using the android.support.test.runner.AndroidJUnitRunner. 
CodeCoverageTest A Test that runs an instrumentation test package on a given device and generates the code coverage report. 


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

Summary

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

Public constructors

InstrumentationTest()

Public methods

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).

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 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)
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)
void setLogcatOnFailureSize(int logcatOnFailureSize)
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)
void setRebootBeforeReRun(boolean rebootBeforeReRun)
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)
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(int timeout)

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

void setTestsToRun(Collection<TestIdentifier> 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

long TEST_COLLECTION_TIMEOUT_MS

default timeout for tests collection

Constant Value: 120000 (0x000000000001d4c0)

TEST_TIMEOUT_INST_ARGS_KEY

String TEST_TIMEOUT_INST_ARGS_KEY

instrumentation test runner argument key used for individual test timeout

Constant Value: "timeout_msec"

Public constructors

InstrumentationTest

InstrumentationTest ()

Public methods

addInstrumentationArg

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

IAbi getAbi ()

Returns
IAbi

getCoverageTarget

String getCoverageTarget ()

Get the coverageTarget previously set via setCoverageTarget(String).

Returns
String

getDevice

ITestDevice getDevice ()

Get the device under test.

Returns
ITestDevice the ITestDevice

getForceAbi

String getForceAbi ()

Returns
String

getMaxTimeout

long getMaxTimeout ()

Returns the max timeout set for the instrumentation.

Returns
long

getPackageName

String getPackageName ()

Get the Android manifest package to run.

Returns
String

getRunName

String getRunName ()

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

Returns
String

getRunnerName

String getRunnerName ()

Gets the Android instrumentation runner to be used.

Returns
String

isResumable

boolean isResumable ()

Returns
boolean

run

void run (ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

Parameters
listener ITestInvocationListener: the ITestInvocationListener of test results

Throws
DeviceNotAvailableException

setAbi

void setAbi (IAbi abi)

Parameters
abi IAbi

setBugreportFrequency

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

void setClassName (String testClassName)

Optionally, set the test class name to run.

Parameters
testClassName String

setCollectTestsOnly

void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

setCollectsTestsShellTimeout

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

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

setDevice

void setDevice (ITestDevice device)

Inject the device under test.

Parameters
device ITestDevice: the ITestDevice to use

setEnforceFormat

void setEnforceFormat (boolean enforce)

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

Parameters
enforce boolean

setFallbackToSerialRerun

void setFallbackToSerialRerun (boolean reRunSerially)

Parameters
reRunSerially boolean

setForceAbi

void setForceAbi (String abi)

Sets force-abi option.

setInstallFile

void setInstallFile (File installFile)

Set the optional file to install that contains the tests.

Parameters
installFile File: the installable File

setLogcatOnFailure

void setLogcatOnFailure (boolean logcatOnFailure)

Parameters
logcatOnFailure boolean

setLogcatOnFailureSize

void setLogcatOnFailureSize (int logcatOnFailureSize)

Parameters
logcatOnFailureSize int

setMethodName

void setMethodName (String testMethodName)

Optionally, set the test method to run.

Parameters
testMethodName String

setPackageName

void setPackageName (String packageName)

Set the Android manifest package to run.

Parameters
packageName String

setReRunUsingTestFile

void setReRunUsingTestFile (boolean reRunUsingTestFile)

Parameters
reRunUsingTestFile boolean

setRebootBeforeReRun

void setRebootBeforeReRun (boolean rebootBeforeReRun)

Parameters
rebootBeforeReRun boolean

setRerunMode

void setRerunMode (boolean rerun)

Optionally, set the rerun mode.

Parameters
rerun boolean

setResumeMode

void setResumeMode (boolean resume)

Optionally, set the resume mode.

Parameters
resume boolean

setRunName

void setRunName (String runName)

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

Parameters
runName String

setRunnerName

void setRunnerName (String runnerName)

Optionally, set the Android instrumentation runner to use.

Parameters
runnerName String

setScreenshotOnFailure

void setScreenshotOnFailure (boolean screenshotOnFailure)

Parameters
screenshotOnFailure boolean

setShellTimeout

void setShellTimeout (long timeout)

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

Parameters
timeout long

setTestFilePathOnDevice

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

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

void setTestSize (String size)

Optionally, set the test size to run.

Parameters
size String

setTestTimeout

void setTestTimeout (int timeout)

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

Parameters
timeout int

setTestsToRun

void setTestsToRun (Collection<TestIdentifier> tests)

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

Parameters
tests Collection: the tests to run

Protected methods

getListInstrumentationParser

ListInstrumentationParser getListInstrumentationParser ()

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

Returns
ListInstrumentationParser

queryRunnerName

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

void setRunnerArgs (IRemoteAndroidTestRunner runner)

Parameters
runner IRemoteAndroidTestRunner