InstrumentationTest 测试

public class InstrumentationTest
extends Object implements IAbiReceiver, IConfigurationReceiver, IDeviceTest, IMetricCollectorReceiver, IRemoteTest, ITestCollector

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


在给定设备上运行插桩测试软件包的测试。

摘要

字段

public static final String RUN_TESTS_AS_USER_KEY

public static final String RUN_TESTS_ON_SDK_SANDBOX

protected boolean mDebug

protected boolean mInstrumentSdkInSandbox

protected boolean mInstrumentSdkSandbox

公共构造函数

InstrumentationTest()

公共方法

void addDeviceListeners( extraListeners)

允许向运行程序添加更多自定义监听器

void addInstrumentationArg(String key, String value)

添加运行插桩测试时要提供的参数。

IAbi getAbi()
IConfiguration getConfiguration()

获取此测试的 IConfiguration

String getCoverageTarget()

通过 setCoverageTarget(String) 获取之前设置的覆盖率目标。

boolean getDebug()

获取插桩调试设置。

ITestDevice getDevice()

获取被测设备。

String getForceAbi()
long getMaxTimeout()

返回为插桩设置的最大超时值。

String getPackageName()

获取要运行的 Android 清单软件包。

String getRunName()

获取将提供给监听器的自定义测试运行名称

String getRunnerName()

获取要使用的 Android 插桩运行程序。

boolean isOrchestrator()

返回 ERROR(InstrumentationTest#mOrchestrator/com.android.tradefed.testtype.InstrumentationTest#mOrchestrator InstrumentationTest#mOrchestrator) 的值

void run(TestInformation testInfo, ITestInvocationListener listener)

运行测试,并将结果报告给监听器。

void setAbi(IAbi abi)
void setClassName(String testClassName)

(可选)设置要运行的测试类名称。

void setCollectTestsOnly(boolean shouldCollectTest)

启用或停用测试收集模式

void setCollectsTestsShellTimeout(int timeout)

此方法已被弃用。 此方法为空操作

void setConfiguration(IConfiguration config)

注入正在使用的 IConfiguration

void setCoverageTarget(String coverageTarget)

设置此测试的覆盖率目标。

void setDebug(boolean debug)

设置插桩调试设置。

void setDevice(ITestDevice device)

注入被测设备。

void setEnforceFormat(boolean enforce)

如果我们强制执行插桩的 AJUR 输出格式,则设为 True。

void setForceAbi(String abi)

设置 force-abi 选项。

void setInstallFile(File installFile)

设置包含测试的要安装的可选文件。

void setIsolatedStorage(boolean isolatedStorage)

设置是否使用隔离存储空间。

void setMethodName(String testMethodName)

(可选)设置要运行的测试方法。

void setMetricCollectors( collectors)

设置为测试运行定义的 IMetricCollector 列表。

void setOrchestrator(boolean useOrchestrator)

设置 --orchestrator 选项

void setPackageName(String packageName)

设置要运行的 Android 清单软件包。

void setReRunUsingTestFile(boolean reRunUsingTestFile)

设置 --rerun-from-file 选项。

void setRerunMode(boolean rerun)

(可选)设置重新运行模式。

void setRunName(String runName)

设置将提供给监听器的自定义测试运行名称

void setRunnerName(String runnerName)

(可选)设置要使用的 Android 插桩运行程序。

void setShellTimeout(long timeout)

(可选)设置设备预期 shell 输出的最长时间(以毫秒为单位)。

void setTestFilePathOnDevice(String testFilePathOnDevice)

(可选)设置指向设备上某个文件的路径,该文件应包含一系列的行 要运行的测试类和方法(格式:com.foo.Class#method)。

void setTestPackageName(String testPackageName)

设置测试软件包过滤条件。

void setTestSize(String size)

(可选)设置要运行的测试大小。

void setTestTimeout(long timeout)

(可选)设置每个单独测试运行的最长时间(以毫秒为单位)。

void setTestsToRun( tests)

设置应由此 InstrumentationTest 执行的测试集合。

void setWindowAnimation(boolean windowAnimation)

受保护的方法

static excludeNonExecuted(TestRunResult results)

滤除“NOT_EXECUTED”以及“已跳过”这是为了跟踪需要重新运行的内容

String getClassName()

获取要运行的类名称。

ListInstrumentationParser getListInstrumentationParser()

获取用于解析“pm 列表插桩”的 ListInstrumentationParser查询。

String getMethodName()

获取要运行的测试方法。

String getTestPackageName()

获取要运行的测试 Java 软件包。

String queryRunnerName()

查询设备以供使用的测试运行程序。

void setRunnerArgs(IRemoteAndroidTestRunner runner)

字段

RUN_TESTS_AS_USER_KEY

public static final String RUN_TESTS_AS_USER_KEY

RUN_TESTS_ON_SDK_SANDBOX

public static final String RUN_TESTS_ON_SDK_SANDBOX

mDebug

protected boolean mDebug

mInstrumentSdkInSandbox

protected boolean mInstrumentSdkInSandbox

mInstrumentSdkSandbox

protected boolean mInstrumentSdkSandbox

公共构造函数

InstrumentationTest 测试

public InstrumentationTest ()

公共方法

addDeviceListeners

public void addDeviceListeners ( extraListeners)

允许向运行程序添加更多自定义监听器

参数
extraListeners

addInstrumentationArg

public void addInstrumentationArg (String key, 
                String value)

添加运行插桩测试时要提供的参数。

参数
key String:参数名称

value String:参数值

getAbi

public IAbi getAbi ()

返回
IAbi

getConfiguration

public IConfiguration getConfiguration ()

获取此测试的 IConfiguration

返回
IConfiguration

getCoverageTarget

public String getCoverageTarget ()

通过 setCoverageTarget(String) 获取之前设置的 ReachTarget。

返回
String

获取调试

public boolean getDebug ()

获取插桩调试设置。

返回
boolean 布尔值调试设置。

getDevice

public ITestDevice getDevice ()

获取被测设备。

返回
ITestDevice ITestDevice

getForceAbi

public String getForceAbi ()

返回
String

getMaxTimeout

public long getMaxTimeout ()

返回为插桩设置的最大超时值。

返回
long

getPackageName

public String getPackageName ()

获取要运行的 Android 清单软件包。

返回
String

getRunName

public String getRunName ()

获取将提供给监听器的自定义测试运行名称

返回
String

getRunnerName

public String getRunnerName ()

获取要使用的 Android 插桩运行程序。

返回
String

得分

public void run (TestInformation testInfo, 
                ITestInvocationListener listener)

运行测试,并将结果报告给监听器。

参数
testInfo TestInformation:包含要运行的有用信息的 TestInformation 对象 测试。

listener ITestInvocationListener:测试结果的 ITestInvocationListener

抛出
DeviceNotAvailableException

SetAbi

public void setAbi (IAbi abi)

参数
abi IAbi

setClassName

public void setClassName (String testClassName)

(可选)设置要运行的测试类名称。

参数
testClassName String

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

启用或停用测试收集模式

setCollectsTestsShellTimeout

public void setCollectsTestsShellTimeout (int timeout)

此方法已废弃。
此方法为空操作

设置允许“max time to shell output response”(最长时间 shell 输出响应)的时间(以毫秒为单位)收集 测试。

参数
timeout int

setConfiguration

public void setConfiguration (IConfiguration config)

注入正在使用的 IConfiguration

参数
config IConfiguration

setCoverageTarget

public void setCoverageTarget (String coverageTarget)

设置此测试的覆盖率目标。

目前未使用。该方法仅存在,以便稍后可以通过 getCoverageTarget()

参数
coverageTarget String

setDebug

public void setDebug (boolean debug)

设置插桩调试设置。

参数
debug boolean:要设为插桩调试设置的布尔值。

setDevice

public void setDevice (ITestDevice device)

注入被测设备。

参数
device ITestDevice:要使用的 ITestDevice

setEnforceFormat

public void setEnforceFormat (boolean enforce)

如果我们强制执行插桩的 AJUR 输出格式,则设为 True。

参数
enforce boolean

setForceAbi

public void setForceAbi (String abi)

设置 force-abi 选项。

setInstallFile

public void setInstallFile (File installFile)

设置包含测试的要安装的可选文件。

参数
installFile File:可安装的 ERROR(/File)

setIsolatedStorage

public void setIsolatedStorage (boolean isolatedStorage)

设置是否使用隔离存储空间。

参数
isolatedStorage boolean

setMethodName

public void setMethodName (String testMethodName)

(可选)设置要运行的测试方法。

参数
testMethodName String

setMetricCollector

public void setMetricCollectors ( collectors)

设置为测试运行定义的 IMetricCollector 列表。

参数
collectors

setOrchestrator

public void setOrchestrator (boolean useOrchestrator)

设置 --orchestrator 选项

参数
useOrchestrator boolean

setPackageName

public void setPackageName (String packageName)

设置要运行的 Android 清单软件包。

参数
packageName String

setReRunUsingTestFile

public void setReRunUsingTestFile (boolean reRunUsingTestFile)

设置 --rerun-from-file 选项。

参数
reRunUsingTestFile boolean

setRerunMode

public void setRerunMode (boolean rerun)

(可选)设置重新运行模式。

参数
rerun boolean

setRunName

public void setRunName (String runName)

设置将提供给监听器的自定义测试运行名称

参数
runName String

setRunnerName

public void setRunnerName (String runnerName)

(可选)设置要使用的 Android 插桩运行程序。

参数
runnerName String

setShellTimeout

public void setShellTimeout (long timeout)

(可选)设置设备预期 shell 输出的最长时间(以毫秒为单位)。

参数
timeout long

setTestFilePathOnDevice

public void setTestFilePathOnDevice (String testFilePathOnDevice)

(可选)设置指向设备上某个文件的路径,该文件应包含一系列的行 要运行的测试类和方法(格式:com.foo.Class#method)。如果设置,则会 通过 InstrumentationFileTest 自动尝试使用此测试文件重新运行测试,而不是为每个其余测试执行单独的 adb 命令 重新运行实验。

参数
testFilePathOnDevice String

setTestPackageName

public void setTestPackageName (String testPackageName)

设置测试软件包过滤条件。

如果为非 null 值,则将仅执行给定 Java 软件包中的测试。

如果向 setClassName(String) 提供了非 null 值,则会被忽略

参数
testPackageName String

setTestSize

public void setTestSize (String size)

(可选)设置要运行的测试大小。

参数
size String

setTestTimeout

public void setTestTimeout (long timeout)

(可选)设置每个单独测试运行的最长时间(以毫秒为单位)。

参数
timeout long

setTestsToRun

public void setTestsToRun ( tests)

设置应由此 InstrumentationTest 执行的测试集合。

参数
tests :要运行的测试

setWindowAnimation

public void setWindowAnimation (boolean windowAnimation)

参数
windowAnimation boolean

受保护的方法

排除非执行

protected static  excludeNonExecuted (TestRunResult results)

滤除“NOT_EXECUTED”为跟踪需要重新运行的内容而跳过了和已跳过。

参数
results TestRunResult

返回

getClassName

protected String getClassName ()

获取要运行的类名称。

返回
String

getListInstrumentationParser

protected ListInstrumentationParser getListInstrumentationParser ()

获取用于解析“pm 列表插桩”的 ListInstrumentationParser查询。

返回
ListInstrumentationParser

getMethodName

protected String getMethodName ()

获取要运行的测试方法。

返回
String

getTestPackageName

protected String getTestPackageName ()

获取要运行的测试 Java 软件包。

返回
String

queryRunnerName

protected String queryRunnerName ()

查询设备以供使用的测试运行程序。

返回
String 第一个与软件包匹配的测试运行程序名称,如果找不到任何名称,则返回 null。

抛出
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

setRunnerArgs

protected void setRunnerArgs (IRemoteAndroidTestRunner runner)

参数
runner IRemoteAndroidTestRunner