HostTest

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

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


A test runner for JUnit host based tests. If the test to be run implements IDeviceTest this runner will pass a reference to the device.

Summary

Nested classes

enum HostTest.ShardUnit

 

Constants

String SET_OPTION_DESC

String SET_OPTION_NAME

Public constructors

HostTest()

Public methods

void addAllExcludeAnnotation(Set<String> notAnnotations)

Adds a Set of annotations to exclude if a tests if marked with it.

void addAllExcludeFilters(Set<String> filters)

Adds the Set of filters of which tests to exclude.

void addAllIncludeAnnotation(Set<String> annotations)

Adds a Set of annotations to include if a tests if marked with it.

void addAllIncludeFilters(Set<String> filters)

Adds the Set of filters of which tests to include.

void addExcludeAnnotation(String notAnnotation)

Adds an annotation to exclude if a tests if marked with it.

void addExcludeFilter(String filter)

Adds a filter of which tests to exclude.

void addIncludeAnnotation(String annotation)

Adds an annotation to include if a tests if marked with it.

void addIncludeFilter(String filter)

Adds a filter of which tests to include.

int countTestCases()

Return the number of test cases across all classes part of the tests

IAbi getAbi()

Set<String> getClassNames()
ITestDevice getDevice()

Get the device under test.

long getRuntimeHint()

Return the expected runtime of the test in milliseconds.

IRemoteTest getTestShard(int shardCount, int shardIndex)

Returns a IRemoteTest for a single shard.

void run(ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

void setAbi(IAbi abi)

void setBuild(IBuildInfo buildInfo)

void setCollectTestsOnly(boolean shouldCollectTest)

Enables or disables test collection mode

void setDevice(ITestDevice device)

Inject the device under test.

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

Helper for Device Runners to use to set options the same way as HostTest, from set-option.

Collection<IRemoteTest> split(int shardCount)

We split by individual by either test class or method.

Protected methods

HostTest createHostTest(Class<?> classObj)

Helper to create a HostTest instance when sharding.

IBuildInfo getBuild()

Get the build info received by HostTest.

ClassLoader getClassLoader()

Returns the default classloader.

List<Class<?>> getClasses()
boolean hasJUnit4Annotation(Class<?> classObj)

Helper to determine if we are dealing with a Test class with Junit4 annotations.

Object loadObject(Class<?> classObj)

load the class object and set the test info (device, build).

void setClassName(String className)

Clear then set a class name to be run.

boolean shouldTestRun(AnnotatedElement annotatedElement)

Check if an elements that has annotation pass the filter.

Constants

SET_OPTION_DESC

String SET_OPTION_DESC

Constant Value: "Options to be passed down to the class under test, key and value should be separated by colon ":"; for example, if class under test supports "--iteration 1" from a command line, it should be passed in as "--set-option iteration:1" or "--set-option iteration:key=value" for passing options to map; escaping of ":" "=" is currently not supported"

SET_OPTION_NAME

String SET_OPTION_NAME

Constant Value: "set-option"

Public constructors

HostTest

HostTest ()

Public methods

addAllExcludeAnnotation

void addAllExcludeAnnotation (Set<String> notAnnotations)

Adds a Set of annotations to exclude if a tests if marked with it.

Parameters
notAnnotations Set

addAllExcludeFilters

void addAllExcludeFilters (Set<String> filters)

Adds the Set of filters of which tests to exclude.

Parameters
filters Set

addAllIncludeAnnotation

void addAllIncludeAnnotation (Set<String> annotations)

Adds a Set of annotations to include if a tests if marked with it.

Parameters
annotations Set

addAllIncludeFilters

void addAllIncludeFilters (Set<String> filters)

Adds the Set of filters of which tests to include.

Parameters
filters Set

addExcludeAnnotation

void addExcludeAnnotation (String notAnnotation)

Adds an annotation to exclude if a tests if marked with it.

Parameters
notAnnotation String

addExcludeFilter

void addExcludeFilter (String filter)

Adds a filter of which tests to exclude.

Parameters
filter String

addIncludeAnnotation

void addIncludeAnnotation (String annotation)

Adds an annotation to include if a tests if marked with it.

Parameters
annotation String

addIncludeFilter

void addIncludeFilter (String filter)

Adds a filter of which tests to include.

Parameters
filter String

countTestCases

int countTestCases ()

Return the number of test cases across all classes part of the tests

Returns
int

getAbi

IAbi getAbi ()

Returns
IAbi

getClassNames

Set<String> getClassNames ()

Returns
Set<String>

getDevice

ITestDevice getDevice ()

Get the device under test.

Returns
ITestDevice the ITestDevice

getRuntimeHint

long getRuntimeHint ()

Return the expected runtime of the test in milliseconds. The time is used to load balance sharded execution

Returns
long

getTestShard

IRemoteTest getTestShard (int shardCount, 
                int shardIndex)

Returns a IRemoteTest for a single shard. This must be deterministic and always return the same IRemoteTest for the same input.

Parameters
shardCount int: the number of total shards

shardIndex int: the index of a test shard to return. The value is in range [0, shardCount).

Returns
IRemoteTest a IRemoteTest

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

setBuild

void setBuild (IBuildInfo buildInfo)

Parameters
buildInfo IBuildInfo

setCollectTestsOnly

void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

setDevice

void setDevice (ITestDevice device)

Inject the device under test.

Parameters
device ITestDevice: the ITestDevice to use

setOptionToLoadedObject

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

Helper for Device Runners to use to set options the same way as HostTest, from set-option.

Parameters
testObj Object: the object that will receive the options.

keyValueOptions List: the list of options formatted as HostTest set-option requires.

split

Collection<IRemoteTest> split (int shardCount)

We split by individual by either test class or method.

Parameters
shardCount int: the attempted shard count.

Returns
Collection<IRemoteTest> a collection of subtests to be executed separately or null if test is not currently shardable

Protected methods

createHostTest

HostTest createHostTest (Class<?> classObj)

Helper to create a HostTest instance when sharding. Override to return any child from HostTest.

Parameters
classObj Class

Returns
HostTest

getBuild

IBuildInfo getBuild ()

Get the build info received by HostTest.

Returns
IBuildInfo the IBuildInfo

getClassLoader

ClassLoader getClassLoader ()

Returns the default classloader.

Returns
ClassLoader

getClasses

List<Class<?>> getClasses ()

Returns
List<Class<?>>

Throws
IllegalArgumentException

hasJUnit4Annotation

boolean hasJUnit4Annotation (Class<?> classObj)

Helper to determine if we are dealing with a Test class with Junit4 annotations.

Parameters
classObj Class

Returns
boolean

loadObject

Object loadObject (Class<?> classObj)

load the class object and set the test info (device, build).

Parameters
classObj Class

Returns
Object

setClassName

void setClassName (String className)

Clear then set a class name to be run.

Parameters
className String

shouldTestRun

boolean shouldTestRun (AnnotatedElement annotatedElement)

Check if an elements that has annotation pass the filter. Exposed for unit testing.

Returns
boolean false if the test should not run.