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

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

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.

Collection<IRemoteTest> split()

We split by --class, and if each individual IRemoteTest is splitable we split them too.

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.

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

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

split

Collection<IRemoteTest> split ()

We split by --class, and if each individual IRemoteTest is splitable we split them too.

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.