仪器仪表测试
public class InstrumentationTest
extends Object
implements IDeviceTest , IRemoteTest , ITestCollector , IAbiReceiver , IConfigurationReceiver , IMetricCollectorReceiver
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
|
公共构造函数 | |
---|---|
InstrumentationTest () |
公共方法 | |
---|---|
void | addDeviceListeners ( extraListeners) addDeviceListeners ( extraListeners) 允许向运行器添加更多自定义侦听器 |
void | addInstrumentationArg (String key, String value) 添加一个参数以在运行仪器测试时提供。 |
IAbi | getAbi () |
IConfiguration | getConfiguration () 获取此测试的 |
String | getCoverageTarget () 获取之前通过 |
boolean | getDebug () 获取仪器调试设置。 |
ITestDevice | getDevice () 获取被测设备。 |
String | getForceAbi () |
long | getMaxTimeout () 返回为检测设置的最大超时。 |
String | getPackageName () 获取要运行的 Android 清单包。 |
String | getRunName () 获取将提供给侦听器的自定义测试运行名称 |
String | getRunnerName () 获取要使用的 Android Instrumentation 运行程序。 |
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) 注入正在使用的 |
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) setMetricCollectors ( collectors) 设置为测试运行定义的 |
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) setTestsToRun ( tests) 设置应由此 InstrumentationTest 执行的测试集合。 |
void | setWindowAnimation (boolean windowAnimation) |
受保护的方法 | |
---|---|
static | excludeNonExecuted ( TestRunResult results) 过滤掉“NOT_EXECUTED”以跟踪需要重新运行的内容。 |
String | getClassName () 获取要运行的类名。 |
ListInstrumentationParser | getListInstrumentationParser () 获取用于解析“pm list Instrumentation”查询的 |
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
调试工具
protected boolean mDebug
公共构造函数
仪器仪表测试
public InstrumentationTest ()
公共方法
添加设备监听器
public void addDeviceListeners (extraListeners)
允许向运行器添加更多自定义侦听器
参数 | |
---|---|
extraListeners |
添加InstrumentationArg
public void addInstrumentationArg (String key, String value)
添加一个参数以在运行仪器测试时提供。
参数 | |
---|---|
key | String : 参数名称 |
value | String : 参数值 |
获取调试信息
public boolean getDebug ()
获取仪器调试设置。
退货 | |
---|---|
boolean | 布尔调试设置。 |
获取力量Abi
public String getForceAbi ()
退货 | |
---|---|
String |
获取最大超时时间
public long getMaxTimeout ()
返回为检测设置的最大超时。
退货 | |
---|---|
long |
获取包名
public String getPackageName ()
获取要运行的 Android 清单包。
退货 | |
---|---|
String |
获取运行名称
public String getRunName ()
获取将提供给侦听器的自定义测试运行名称
退货 | |
---|---|
String |
获取跑步者姓名
public String getRunnerName ()
获取要使用的 Android Instrumentation 运行程序。
退货 | |
---|---|
String |
跑步
public void run (TestInformation testInfo, ITestInvocationListener listener)
运行测试,并将结果报告给侦听器。
参数 | |
---|---|
testInfo | TestInformation : TestInformation 对象包含运行测试的有用信息。 |
listener | ITestInvocationListener :测试结果的ITestInvocationListener |
投掷 | |
---|---|
DeviceNotAvailableException |
设置类名
public void setClassName (String testClassName)
(可选)设置要运行的测试类名称。
参数 | |
---|---|
testClassName | String |
仅设置收集测试
public void setCollectTestsOnly (boolean shouldCollectTest)
启用或禁用测试收集模式
setCollectsTestsShellTimeout
public void setCollectsTestsShellTimeout (int timeout)
此方法已被弃用。
该方法是无操作的
设置最大时间(以毫秒为单位),以在收集测试时允许“shell 输出响应的最大时间”。
参数 | |
---|---|
timeout | int |
设置配置
public void setConfiguration (IConfiguration config)
注入正在使用的IConfiguration
。
参数 | |
---|---|
config | IConfiguration |
设置覆盖目标
public void setCoverageTarget (String coverageTarget)
设置本次测试的覆盖率目标。
目前未使用。此方法只是存在,因此以后可以通过getCoverageTarget()
检索coverageTarget
参数 | |
---|---|
coverageTarget | String |
设置调试
public void setDebug (boolean debug)
设置仪器调试设置。
参数 | |
---|---|
debug | boolean :用于设置仪器调试设置的布尔值。 |
设置强制格式
public void setEnforceFormat (boolean enforce)
如果我们强制执行检测的 AJUR 输出格式,则设置为 True。
参数 | |
---|---|
enforce | boolean |
设置强制Abi
public void setForceAbi (String abi)
设置force-abi选项。
设置安装文件
public void setInstallFile (File installFile)
设置要安装的包含测试的可选文件。
参数 | |
---|---|
installFile | File :可安装ERROR(/File) |
设置隔离存储
public void setIsolatedStorage (boolean isolatedStorage)
设置是否使用隔离存储。
参数 | |
---|---|
isolatedStorage | boolean |
设置方法名
public void setMethodName (String testMethodName)
(可选)设置要运行的测试方法。
参数 | |
---|---|
testMethodName | String |
设置MetricCollectors
public void setMetricCollectors (collectors)
设置为测试运行定义的IMetricCollector
列表。
参数 | |
---|---|
collectors |
设置包名
public void setPackageName (String packageName)
设置要运行的 Android 清单包。
参数 | |
---|---|
packageName | String |
设置重新运行使用测试文件
public void setReRunUsingTestFile (boolean reRunUsingTestFile)
设置 --rerun-from-file 选项。
参数 | |
---|---|
reRunUsingTestFile | boolean |
设置重新运行模式
public void setRerunMode (boolean rerun)
(可选)设置重新运行模式。
参数 | |
---|---|
rerun | boolean |
设置运行名称
public void setRunName (String runName)
设置将提供给侦听器的自定义测试运行名称
参数 | |
---|---|
runName | String |
设置跑步者名称
public void setRunnerName (String runnerName)
(可选)设置要使用的 Android 仪器运行程序。
参数 | |
---|---|
runnerName | String |
设置Shell超时
public void setShellTimeout (long timeout)
(可选)设置设备期望 shell 输出的最长时间(以毫秒为单位)。
参数 | |
---|---|
timeout | long |
在设备上设置测试文件路径
public void setTestFilePathOnDevice (String testFilePathOnDevice)
(可选)设置设备上文件的路径,该文件应包含要运行的行分隔测试类和方法的列表(格式:com.foo.Class#method)。如果设置,将自动尝试通过 InstrumentationFileTest 使用此测试文件重新运行测试,而不是通过重新运行为每个剩余测试执行单独的 adb 命令。
参数 | |
---|---|
testFilePathOnDevice | String |
设置测试包名称
public void setTestPackageName (String testPackageName)
设置测试包过滤器。
如果非 null,则仅执行给定 java 包内的测试。
如果为setClassName(String)
提供了非空值,则将被忽略
参数 | |
---|---|
testPackageName | String |
设置测试大小
public void setTestSize (String size)
(可选)设置要运行的测试大小。
参数 | |
---|---|
size | String |
设置测试超时
public void setTestTimeout (long timeout)
(可选)设置每个单独测试运行的最长时间(以毫秒为单位)。
参数 | |
---|---|
timeout | long |
设置要运行的测试
public void setTestsToRun (tests)
设置应由此 InstrumentationTest 执行的测试集合。
参数 | |
---|---|
tests |
设置窗口动画
public void setWindowAnimation (boolean windowAnimation)
参数 | |
---|---|
windowAnimation | boolean |
受保护的方法
排除未执行
protected staticexcludeNonExecuted (TestRunResult results)
过滤掉“NOT_EXECUTED”以跟踪需要重新运行的内容。
参数 | |
---|---|
results | TestRunResult |
退货 | |
---|---|
获取类名
protected String getClassName ()
获取要运行的类名。
退货 | |
---|---|
String |
获取ListInstrumentationParser
protected ListInstrumentationParser getListInstrumentationParser ()
获取用于解析“pm list Instrumentation”查询的ListInstrumentationParser
。
退货 | |
---|---|
ListInstrumentationParser |
获取方法名
protected String getMethodName ()
运行测试方法。
退货 | |
---|---|
String |
获取测试包名称
protected String getTestPackageName ()
获取要运行的测试java包。
退货 | |
---|---|
String |
查询运行者名称
protected String queryRunnerName ()
查询测试运行器要使用的设备。
退货 | |
---|---|
String | 与包匹配的第一个测试运行程序名称,如果找不到任何名称,则返回 null。 |
投掷 | |
---|---|
| com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
设置RunnerArgs
protected void setRunnerArgs (IRemoteAndroidTestRunner runner)
参数 | |
---|---|
runner | IRemoteAndroidTestRunner |