BaseHostJUnit4测试

public abstract class BaseHostJUnit4Test
extends Object implements IAbiReceiver , ITestInformationReceiver

java.lang.Object
com.android.tradefed.testtype.junit4.BaseHostJUnit4Test


用于运行主机 JUnit4 样式测试的基测试类。此类提供从主机端安装、运行和清理仪器测试的支持。该类是多设备兼容的。应该是从主机端运行仪器测试的单一事实来源,以避免重复的实用程序和基类。

概括

公共构造函数

BaseHostJUnit4Test ()

公共方法

final void autoTearDown ()

自动拆卸所有已安装的 apk。

final IAbi getAbi ()
final IBuildInfo getBuild ()
final ITestDevice getDevice ()
final IInvocationContext getInvocationContext ()
final TestRunResult getLastDeviceRunResults ()

返回最新运行的 runDeviceTests 产生的TestRunResult

final getListDevices ()
TestInformation getTestInformation ()
boolean hasDeviceFeature (String feature)
final void installPackage ( DeviceTestRunOptions options)

根据设备上的DeviceTestRunOptions安装apk。

final void installPackage (String apkFileName, String... options)

在设备上安装指定名称的 apk。

final void installPackage ( ITestDevice device, String apkFileName, String... options)

在给定设备上安装指定名称的 apk。

final void installPackageAsUser ( ITestDevice device, String apkFileName, boolean grantPermission, int userId, String... options)

在给定设备上为特定用户安装指定名称的 apk。

final void installPackageAsUser (String apkFileName, boolean grantPermission, int userId, String... options)

为特定用户安装指定名称的 apk。

final boolean isPackageInstalled (String pkg)

检查设备上是否安装了给定名称的软件包

final boolean isPackageInstalled ( ITestDevice device, String pkg)

检查设备上是否安装了给定名称的软件包

final boolean runDeviceTests ( ITestDevice device, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs)

运行已安装的检测包的方法。

final boolean runDeviceTests ( ITestDevice device, String pkgName, String testClassName, String testMethodName, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs)

运行已安装的检测包的方法。

final boolean runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, instrumentationArgs, extraListeners)

运行已安装的检测包的方法。

final boolean runDeviceTests ( ITestDevice device, String pkgName, String testClassName, String testMethodName, Long testTimeoutMs)

运行已安装的检测包的方法。

final boolean runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, instrumentationArgs) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, instrumentationArgs)

运行已安装的检测包的方法。

final boolean runDeviceTests (String pkgName, String testClassName, String testMethodName)

运行已安装的检测包的方法。

final boolean runDeviceTests ( DeviceTestRunOptions options)

根据DeviceTestRunOptions中的信息运行检测。

final boolean runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, boolean isRestartDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, boolean isRestartDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, boolean isRestartDisabled, instrumentationArgs, extraListeners)

运行已安装的检测包的方法。

final boolean runDeviceTests ( ITestDevice device, String pkgName, String testClassName, String testMethodName)

运行已安装的检测包的方法。

final boolean runDeviceTests (String pkgName, String testClassName, Integer userId, Long testTimeoutMs)

运行已安装的检测包的方法。

final boolean runDeviceTests (String pkgName, String testClassName)

运行已安装的检测包的方法。

final boolean runDeviceTests (String pkgName, String testClassName, Long testTimeoutMs)

运行已安装的检测包的方法。

final boolean runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, instrumentationArgs, extraListeners)

运行已安装的检测包的方法。

final boolean runDeviceTests (String runner, String pkgName, String testClassName, String testMethodName)

运行已安装的检测包的方法。

final void setAbi ( IAbi abi)
final void setTestInformation ( TestInformation testInformation)
final String uninstallPackage (String pkgName)

卸载设备上的软件包。

final String uninstallPackage ( ITestDevice device, String pkgName)

卸载设备上的软件包

公共构造函数

BaseHostJUnit4测试

public BaseHostJUnit4Test ()

公共方法

自动拆卸

public final void autoTearDown ()

自动拆卸所有已安装的 apk。这将从安装的设备上卸载所有 apk。

投掷
DeviceNotAvailableException

获取阿比

public final IAbi getAbi ()

退货
IAbi

获取构建

public final IBuildInfo getBuild ()

退货
IBuildInfo

获取设备

public final ITestDevice getDevice ()

退货
ITestDevice

获取调用上下文

public final IInvocationContext getInvocationContext ()

退货
IInvocationContext

获取最后设备运行结果

public final TestRunResult getLastDeviceRunResults ()

返回最新运行的 runDeviceTests 产生的TestRunResult 。如果没有可用结果,则返回 null。

退货
TestRunResult

获取设备列表

public final  getListDevices ()

退货

获取测试信息

public TestInformation getTestInformation ()

退货
TestInformation

有设备功能

public boolean hasDeviceFeature (String feature)

参数
feature String

退货
boolean

投掷
DeviceNotAvailableException

安装包

public final void installPackage (DeviceTestRunOptions options)

根据设备上的DeviceTestRunOptions安装apk。 Apk 将被自动清理。

参数
options DeviceTestRunOptions :软件包安装的选项。

投掷
DeviceNotAvailableException
TargetSetupError

安装包

public final void installPackage (String apkFileName, 
                String... options)

在设备上安装指定名称的 apk。 Apk 将被自动清理。

参数
apkFileName String : apk 文件的名称。

options String : 为安装命令提供的额外选项

投掷
DeviceNotAvailableException
TargetSetupError

安装包

public final void installPackage (ITestDevice device, 
                String apkFileName, 
                String... options)

在给定设备上安装指定名称的 apk。 Apk 将被自动清理。

参数
device ITestDevice :要安装 apk 的ITestDevice

apkFileName String : apk 文件的名称。

options String : 为安装命令提供的额外选项

投掷
DeviceNotAvailableException
TargetSetupError

以用户身份安装包

public final void installPackageAsUser (ITestDevice device, 
                String apkFileName, 
                boolean grantPermission, 
                int userId, 
                String... options)

在给定设备上为特定用户安装指定名称的 apk。

参数
device ITestDevice :要安装 apk 的ITestDevice

apkFileName String : apk 文件的名称。

grantPermission boolean : 安装apk时是否传递授予权限标志。

userId int :安装 apk 的用户的用户 ID。

options String : 为安装命令提供的额外选项

投掷
DeviceNotAvailableException
TargetSetupError

以用户身份安装包

public final void installPackageAsUser (String apkFileName, 
                boolean grantPermission, 
                int userId, 
                String... options)

为特定用户安装指定名称的 apk。

参数
apkFileName String : apk 文件的名称。

grantPermission boolean : 安装apk时是否传递授予权限标志。

userId int :安装 apk 的用户的用户 ID。

options String : 为安装命令提供的额外选项

投掷
DeviceNotAvailableException
TargetSetupError

软件包已安装

public final boolean isPackageInstalled (String pkg)

检查设备上是否安装了给定名称的软件包

参数
pkg String : 包的名称

退货
boolean如果在设备上找到该包则为 true

投掷
DeviceNotAvailableException

软件包已安装

public final boolean isPackageInstalled (ITestDevice device, 
                String pkg)

检查设备上是否安装了给定名称的软件包

参数
device ITestDevice :应卸载软件包的设备。

pkg String : 包的名称

退货
boolean如果在设备上找到该包则为 true

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (ITestDevice device, 
                String pkgName, 
                String testClassName, 
                String testMethodName, 
                Integer userId, 
                Long testTimeoutMs)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
device ITestDevice :运行检测的设备。

pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

userId Integer :要运行测试的用户的 ID。可以为空。

testTimeoutMs Long :应用于每个测试用例的超时(以毫秒为单位)。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (ITestDevice device, 
                String pkgName, 
                String testClassName, 
                String testMethodName, 
                Long testTimeoutMs, 
                Long maxTimeToOutputMs, 
                Long maxInstrumentationTimeoutMs)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
device ITestDevice :运行检测的设备。

pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

testTimeoutMs Long :应用于每个测试用例的超时(以毫秒为单位)。

maxTimeToOutputMs Long :测试开始输出内容的最大超时时间。

maxInstrumentationTimeoutMs Long :完整检测必须完成的最大超时。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (ITestDevice device, 
                String runner, 
                String pkgName, 
                String testClassName, 
                String testMethodName, 
                Integer userId, 
                Long testTimeoutMs, 
                Long maxTimeToOutputMs, 
                Long maxInstrumentationTimeoutMs, 
                boolean checkResults, 
                boolean isHiddenApiCheckDisabled, 
                boolean isTestApiCheckDisabled, 
                boolean isIsolatedStorageDisabled, 
                boolean isWindowAnimationDisabled, 
                 instrumentationArgs, 
                 extraListeners)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
device ITestDevice :运行检测的设备。

runner String

pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

userId Integer :要运行测试的用户的 ID。可以为空。

testTimeoutMs Long :应用于每个测试用例的超时(以毫秒为单位)。

maxTimeToOutputMs Long :测试开始输出内容的最大超时时间。

maxInstrumentationTimeoutMs Long :完整检测必须完成的最大超时。

checkResults boolean :是否检查结果是否有崩溃。

isHiddenApiCheckDisabled boolean :我们是否应该禁用隐藏的 api 检查。

isTestApiCheckDisabled boolean :我们是否应该禁用测试 api 检查。

isIsolatedStorageDisabled boolean :我们是否应该禁用独立存储。

isWindowAnimationDisabled boolean :我们是否应该禁用窗口动画。

instrumentationArgs :传递给仪器的参数。

extraListeners

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (ITestDevice device, 
                String pkgName, 
                String testClassName, 
                String testMethodName, 
                Long testTimeoutMs)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
device ITestDevice :运行检测的设备。

pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

testTimeoutMs Long :应用于每个测试用例的超时(以毫秒为单位)。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (ITestDevice device, 
                String runner, 
                String pkgName, 
                String testClassName, 
                String testMethodName, 
                Integer userId, 
                Long testTimeoutMs, 
                Long maxTimeToOutputMs, 
                Long maxInstrumentationTimeoutMs, 
                boolean checkResults, 
                boolean isHiddenApiCheckDisabled, 
                 instrumentationArgs)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
device ITestDevice :运行检测的设备。

runner String

pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

userId Integer :要运行测试的用户的 ID。可以为空。

testTimeoutMs Long :应用于每个测试用例的超时(以毫秒为单位)。

maxTimeToOutputMs Long :测试开始输出内容的最大超时时间。

maxInstrumentationTimeoutMs Long :完整检测必须完成的最大超时。

checkResults boolean :是否检查结果是否有崩溃。

isHiddenApiCheckDisabled boolean :我们是否应该禁用隐藏的 api 检查。

instrumentationArgs :传递给仪器的参数。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (String pkgName, 
                String testClassName, 
                String testMethodName)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (DeviceTestRunOptions options)

根据DeviceTestRunOptions中的信息运行检测。

参数
options DeviceTestRunOptions :驱动仪器设置的DeviceTestRunOptions

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (ITestDevice device, 
                String runner, 
                String pkgName, 
                String testClassName, 
                String testMethodName, 
                Integer userId, 
                Long testTimeoutMs, 
                Long maxTimeToOutputMs, 
                Long maxInstrumentationTimeoutMs, 
                boolean checkResults, 
                boolean isHiddenApiCheckDisabled, 
                boolean isTestApiCheckDisabled, 
                boolean isIsolatedStorageDisabled, 
                boolean isWindowAnimationDisabled, 
                boolean isRestartDisabled, 
                 instrumentationArgs, 
                 extraListeners)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
device ITestDevice :运行检测的设备。

runner String

pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

userId Integer :要运行测试的用户的 ID。可以为空。

testTimeoutMs Long :应用于每个测试用例的超时(以毫秒为单位)。

maxTimeToOutputMs Long :测试开始输出内容的最大超时时间。

maxInstrumentationTimeoutMs Long :完整检测必须完成的最大超时。

checkResults boolean :是否检查结果是否有崩溃。

isHiddenApiCheckDisabled boolean :我们是否应该禁用隐藏的 api 检查。

isTestApiCheckDisabled boolean :我们是否应该禁用测试 api 检查。

isIsolatedStorageDisabled boolean :我们是否应该禁用独立存储。

isWindowAnimationDisabled boolean :我们是否应该禁用窗口动画。

isRestartDisabled boolean

instrumentationArgs :传递给仪器的参数。

extraListeners

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (ITestDevice device, 
                String pkgName, 
                String testClassName, 
                String testMethodName)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
device ITestDevice :运行检测的设备。

pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (String pkgName, 
                String testClassName, 
                Integer userId, 
                Long testTimeoutMs)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

userId Integer :要运行测试的用户的 ID。可以为空。

testTimeoutMs Long :应用于每个测试用例的超时(以毫秒为单位)。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (String pkgName, 
                String testClassName)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (String pkgName, 
                String testClassName, 
                Long testTimeoutMs)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testTimeoutMs Long :应用于每个测试用例的超时(以毫秒为单位)。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (ITestDevice device, 
                String runner, 
                String pkgName, 
                String testClassName, 
                String testMethodName, 
                Integer userId, 
                Long testTimeoutMs, 
                Long maxTimeToOutputMs, 
                Long maxInstrumentationTimeoutMs, 
                boolean checkResults, 
                boolean isHiddenApiCheckDisabled, 
                boolean isTestApiCheckDisabled, 
                boolean isIsolatedStorageDisabled, 
                 instrumentationArgs, 
                 extraListeners)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
device ITestDevice :运行检测的设备。

runner String

pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

userId Integer :要运行测试的用户的 ID。可以为空。

testTimeoutMs Long :应用于每个测试用例的超时(以毫秒为单位)。

maxTimeToOutputMs Long :测试开始输出内容的最大超时时间。

maxInstrumentationTimeoutMs Long :完整检测必须完成的最大超时。

checkResults boolean :是否检查结果是否有崩溃。

isHiddenApiCheckDisabled boolean :我们是否应该禁用隐藏的 api 检查。

isTestApiCheckDisabled boolean :我们是否应该禁用测试 api 检查。

isIsolatedStorageDisabled boolean :我们是否应该禁用独立存储。

instrumentationArgs :传递给仪器的参数。

extraListeners

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

运行设备测试

public final boolean runDeviceTests (String runner, 
                String pkgName, 
                String testClassName, 
                String testMethodName)

运行已安装的检测包的方法。之后立即使用getLastDeviceRunResults()来获取结果的详细信息。

参数
runner String :要使用的检测运行器。

pkgName String :要运行的包的名称。

testClassName String :要运行的测试类的名称。

testMethodName String :要运行的类中的测试方法的名称。

退货
boolean如果成功且没有失败,则为真。否则为假。

投掷
DeviceNotAvailableException

设置阿比

public final void setAbi (IAbi abi)

参数
abi IAbi

设置测试信息

public final void setTestInformation (TestInformation testInformation)

参数
testInformation TestInformation

卸载包

public final String uninstallPackage (String pkgName)

卸载设备上的软件包。

参数
pkgName String : 要卸载的 Android 包

退货
String带有错误代码的String ,如果成功则为null

投掷
DeviceNotAvailableException

卸载包

public final String uninstallPackage (ITestDevice device, 
                String pkgName)

卸载设备上的软件包

参数
device ITestDevice :应卸载软件包的设备。

pkgName String : 要卸载的 Android 包

退货
String带有错误代码的String ,如果成功则为null

投掷
DeviceNotAvailableException