HostTest

public class HostTest
extends Object implements IAbiReceiver, IBuildReceiver, IConfigurationReceiver, IDeviceTest, IDiscoverTestClasses, IRemoteTest, IRuntimeHintProvider, IShardableTest, ITestAnnotationFilterReceiver, ITestCollector, ITestFilterReceiver

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


适用于基于 JUnit 主机的测试的测试运行程序。如果要运行的测试实现了 IDeviceTest,此运行程序将传递对设备的引用。

摘要

常量

String SET_OPTION_DESC

String SET_OPTION_NAME

公共构造函数

HostTest()

公共方法

void addAllExcludeAnnotation(Set<String> notAnnotations)

添加了 Set 注解,如果测试标记了该注解,则排除相应测试。

void addAllExcludeFilters(Set<String> filters)

添加用于指定要排除哪些测试的过滤条件Set

void addAllIncludeAnnotation(Set<String> annotations)

添加一个注解 Set,如果测试标记了该注解,则包含该注解。

void addAllIncludeFilters(Set<String> filters)

添加用于指定要包含哪些测试的过滤条件Set

void addExcludeAnnotation(String notAnnotation)

添加了一个注解,用于排除标记了该注解的测试。

void addExcludeFilter(String filter)

添加用于指定要排除哪些测试的过滤条件。

void addIncludeAnnotation(String annotation)

添加一个注解,如果测试标记了该注解,则包含该测试。

void addIncludeFilter(String filter)

添加用于指定要包含哪些测试的过滤条件。

void clearExcludeAnnotations()

删除当前跟踪的所有排除注释。

void clearExcludeFilters()

删除当前跟踪的所有排除过滤条件。

void clearIncludeAnnotations()

删除当前跟踪的所有 include 注释。

void clearIncludeFilters()

删除当前跟踪的所有包含过滤条件。

int countTestCases()

返回测试中所有类的测试用例数量

IAbi getAbi()

Set<String> getClassNames()
ITestDevice getDevice()

获取被测设备。

Set<String> getExcludeAnnotations()

返回要排除的注释的当前 Set

Set<String> getExcludeFilters()

返回当前的排除过滤条件Set

Set<String> getIncludeAnnotations()

返回要包含的注释的当前 Set

Set<String> getIncludeFilters()

返回当前的包含过滤条件Set

long getRuntimeHint()

返回测试的预期运行时长(以毫秒为单位)。

void run(TestInformation testInfo, ITestInvocationListener listener)

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

void setAbi(IAbi abi)

void setBuild(IBuildInfo buildInfo)

void setCollectTestsOnly(boolean shouldCollectTest)

启用或停用测试收集模式

void setConfiguration(IConfiguration configuration)

注入正在使用的 IConfiguration

void setDevice(ITestDevice device)

注入被测设备。

static void setOptionToLoadedObject(Object testObj, List<String> keyValueOptions)

一种辅助程序,供设备运行程序使用,用于以与 HostTest 相同的方式(通过 set-option)设置选项。

void setTestInformation(TestInformation testInfo)
Collection<IRemoteTest> split(Integer shardCount, TestInformation testInfo)

我们按测试类或方法拆分了各个测试。

受保护的方法

HostTest createHostTest(Class<?> classObj)

用于在分片时创建 HostTest 实例的辅助类。

IBuildInfo getBuild()

获取 HostTest 收到的 build 信息。

ClassLoader getClassLoader()

返回默认类加载器。

final List<Class<?>> getClasses()
File getJarFile(String jarName, TestInformation testInfo)

检查工件通常位于的几个位置(针对不同的使用情形),以找到我们的 JAR。

boolean hasJUnit4Annotation(Class<?> classObj)

用于帮助确定我们是否在处理带有 Junit4 注释的测试类。

Object loadObject(Class<?> classObj)

加载类对象并设置测试信息(设备、build)。

void setClassName(String className)

清除然后设置要运行的类名称。

void setMethodName(String methodName)

设置要运行的方法名称。

boolean shouldTestRun(AnnotatedElement annotatedElement)

检查具有注释的元素是否通过了过滤条件。

常量

SET_OPTION_DESC

public static final String SET_OPTION_DESC

常量值: “要传递给被测类的选项,键和值应以英文冒号“:”分隔;例如,如果被测类支持从命令行传递“--iteration 1”,则应将其作为“--set-option iteration:1”或“--set-option iteration:key=value”传递,以将选项传递给映射。包含“:”或“=”的值可以使用反斜杠进行转义。您可以通过指定特定类别来定位该类别。“--set-option :

SET_OPTION_NAME

public static final String SET_OPTION_NAME

常量值: “set-option”

公共构造函数

HostTest

public HostTest ()

公共方法

addAllExcludeAnnotation

public void addAllExcludeAnnotation (Set<String> notAnnotations)

添加了 Set 注解,如果测试标记了该注解,则排除相应测试。

参数
notAnnotations Set

addAllExcludeFilters

public void addAllExcludeFilters (Set<String> filters)

添加用于指定要排除哪些测试的过滤条件Set

参数
filters Set

addAllIncludeAnnotation

public void addAllIncludeAnnotation (Set<String> annotations)

添加一个注解 Set 列表,如果测试标记了这些注解,则包含这些测试。

参数
annotations Set

addAllIncludeFilters

public void addAllIncludeFilters (Set<String> filters)

添加用于指定要包含哪些测试的过滤条件Set

参数
filters Set

addExcludeAnnotation

public void addExcludeAnnotation (String notAnnotation)

添加了一个注解,用于排除标记了该注解的测试。

参数
notAnnotation String

addExcludeFilter

public void addExcludeFilter (String filter)

添加用于指定要排除哪些测试的过滤条件。

参数
filter String

addIncludeAnnotation

public void addIncludeAnnotation (String annotation)

添加了注解,用于指定如果测试标记了该注解,则包含该测试。

参数
annotation String

addIncludeFilter

public void addIncludeFilter (String filter)

添加用于指定要包含哪些测试的过滤条件。

参数
filter String

clearExcludeAnnotations

public void clearExcludeAnnotations ()

删除当前跟踪的所有排除注释。

clearExcludeFilters

public void clearExcludeFilters ()

删除当前跟踪的所有排除过滤条件。

clearIncludeAnnotations

public void clearIncludeAnnotations ()

删除当前跟踪的所有包含注释。

clearIncludeFilters

public void clearIncludeFilters ()

删除当前跟踪的所有包含过滤条件。

countTestCases

public int countTestCases ()

返回测试中所有类的测试用例数量

返回
int

getAbi

public IAbi getAbi ()

返回
IAbi

getClassNames

public Set<String> getClassNames ()

返回
Set<String>

getDevice

public ITestDevice getDevice ()

获取被测设备。

返回
ITestDevice ITestDevice

getExcludeAnnotations

public Set<String> getExcludeAnnotations ()

返回当前要排除的注释的 Set

返回
Set<String>

getExcludeFilters

public Set<String> getExcludeFilters ()

返回当前的排除过滤条件Set

返回
Set<String>

getIncludeAnnotations

public Set<String> getIncludeAnnotations ()

返回要包含的注释的当前 Set

返回
Set<String>

getIncludeFilters

public Set<String> getIncludeFilters ()

返回当前的包含过滤条件Set

返回
Set<String>

getRuntimeHint

public long getRuntimeHint ()

以毫秒为单位返回测试的预期运行时长。 该时间用于对分片执行进行负载均衡

返回
long

run

public void run (TestInformation testInfo, 
                ITestInvocationListener listener)

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

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

listener ITestInvocationListener:测试结果的 ITestInvocationListener

抛出
DeviceNotAvailableException

setAbi

public void setAbi (IAbi abi)

参数
abi IAbi

setBuild

public void setBuild (IBuildInfo buildInfo)

参数
buildInfo IBuildInfo

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

启用或停用测试收集模式

setConfiguration

public void setConfiguration (IConfiguration configuration)

注入正在使用的 IConfiguration

参数
configuration IConfiguration

setDevice

public void setDevice (ITestDevice device)

注入被测设备。

参数
device ITestDevice:要使用的 ITestDevice

setOptionToLoadedObject

public static void setOptionToLoadedObject (Object testObj, 
                List<String> keyValueOptions)

辅助设备运行程序,用于以与 HostTest 相同的方式(通过 set-option)设置选项。

参数
testObj Object:将接收选项的对象。

keyValueOptions List:格式化为 HostTest set-option 所需的选项列表。

setTestInformation

public void setTestInformation (TestInformation testInfo)

参数
testInfo TestInformation

分解

public Collection<IRemoteTest> split (Integer shardCount, 
                TestInformation testInfo)

我们按个人(测试类或方法)进行拆分。

参数
shardCount Integer:尝试分片的数量。

testInfo TestInformation:父级 TestInformation

返回
Collection<IRemoteTest> 要单独执行的子测试集合,如果测试目前无法分片,则为 null

受保护的方法

createHostTest

protected HostTest createHostTest (Class<?> classObj)

用于在分片时创建 HostTest 实例的辅助程序。替换以从 HostTest 返回任何子项。

参数
classObj Class

返回
HostTest

getBuild

protected IBuildInfo getBuild ()

获取 HostTest 收到的 build 信息。

返回
IBuildInfo IBuildInfo

getClassLoader

protected ClassLoader getClassLoader ()

返回默认的类加载器。

返回
ClassLoader

getClasses

protected final List<Class<?>> getClasses ()

返回
List<Class<?>>

抛出
IllegalArgumentException

getJarFile

protected File getJarFile (String jarName, 
                TestInformation testInfo)

检查不同使用情形下工件通常所在的多个位置,以找到我们的 JAR。

参数
jarName String

testInfo TestInformation

返回
File

抛出
FileNotFoundException

hasJUnit4Annotation

protected boolean hasJUnit4Annotation (Class<?> classObj)

用于帮助确定我们是否在处理带有 Junit4 注释的测试类。

参数
classObj Class

返回
boolean

loadObject

protected Object loadObject (Class<?> classObj)

加载类对象并设置测试信息(设备、build)。

参数
classObj Class

返回
Object

setClassName

protected void setClassName (String className)

清除然后设置要运行的类名称。

参数
className String

setMethodName

protected void setMethodName (String methodName)

设置要运行的方法名称。

用于运行测试类中的特定测试方法。

参数
methodName String

shouldTestRun

protected boolean shouldTestRun (AnnotatedElement annotatedElement)

检查具有注释的元素是否通过了过滤条件。公开以用于单元测试。

返回
boolean 如果测试不应运行,则为 false。