HostTest

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

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

Fields

public static final String SET_OPTION_DESC

public static final String SET_OPTION_NAME

Public constructors

HostTest()

Public methods

void addAllExcludeAnnotation( notAnnotations)

Adds a ERROR(/Set) of annotations to exclude if a tests if marked with it.

void addAllExcludeFilters( filters)

Adds the ERROR(/Set) of filters of which tests to exclude.

void addAllIncludeAnnotation( annotations)

Adds a ERROR(/Set) of annotations to include if a tests if marked with it.

void addAllIncludeFilters( filters)

Adds the ERROR(/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.

void clearExcludeAnnotations()

Delete all the exclude annotations currently tracked.

void clearExcludeFilters()

Delete all the exclude filters currently tracked.

void clearIncludeAnnotations()

Delete all the include annotations currently tracked.

void clearIncludeFilters()

Delete all the include filters currently tracked.

int countTestCases()

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

IAbi getAbi()

getClassNames()
ITestDevice getDevice()

Get the device under test.

getExcludeAnnotations()

Returns the current ERROR(/Set) of annotations to exclude.

getExcludeFilters()

Returns the current ERROR(/Set) of exclude filters.

getIncludeAnnotations()

Returns the current ERROR(/Set) of annotations to include.

getIncludeFilters()

Returns the current ERROR(/Set) of include filters.

long getRuntimeHint()

Return the expected runtime of the test in milliseconds.

void run(TestInformation testInfo, 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 setConfiguration(IConfiguration configuration)

Injects the IConfiguration in use.

void setDevice(ITestDevice device)

Inject the device under test.

static void setOptionToLoadedObject(Object testObj, keyValueOptions)

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

void setTestInformation(TestInformation testInfo)
split(Integer shardCount, TestInformation testInfo)

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.

final getClasses()
File getJarFile(String jarName, TestInformation testInfo)

Inspect several location where the artifact are usually located for different use cases to find our jar.

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.

Fields

SET_OPTION_DESC

public static final String SET_OPTION_DESC

SET_OPTION_NAME

public static final String SET_OPTION_NAME

Public constructors

HostTest

public HostTest ()

Public methods

addAllExcludeAnnotation

public void addAllExcludeAnnotation ( notAnnotations)

Adds a ERROR(/Set) of annotations to exclude if a tests if marked with it.

Parameters
notAnnotations

addAllExcludeFilters

public void addAllExcludeFilters ( filters)

Adds the ERROR(/Set) of filters of which tests to exclude.

Parameters
filters

addAllIncludeAnnotation

public void addAllIncludeAnnotation ( annotations)

Adds a ERROR(/Set) of annotations to include if a tests if marked with it.

Parameters
annotations

addAllIncludeFilters

public void addAllIncludeFilters ( filters)

Adds the ERROR(/Set) of filters of which tests to include.

Parameters
filters

addExcludeAnnotation

public void addExcludeAnnotation (String notAnnotation)

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

Parameters
notAnnotation String

addExcludeFilter

public void addExcludeFilter (String filter)

Adds a filter of which tests to exclude.

Parameters
filter String

addIncludeAnnotation

public void addIncludeAnnotation (String annotation)

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

Parameters
annotation String

addIncludeFilter

public void addIncludeFilter (String filter)

Adds a filter of which tests to include.

Parameters
filter String

clearExcludeAnnotations

public void clearExcludeAnnotations ()

Delete all the exclude annotations currently tracked.

clearExcludeFilters

public void clearExcludeFilters ()

Delete all the exclude filters currently tracked.

clearIncludeAnnotations

public void clearIncludeAnnotations ()

Delete all the include annotations currently tracked.

clearIncludeFilters

public void clearIncludeFilters ()

Delete all the include filters currently tracked.

countTestCases

public int countTestCases ()

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

Returns
int

getAbi

public IAbi getAbi ()

Returns
IAbi

getClassNames

public  getClassNames ()

Returns

getDevice

public ITestDevice getDevice ()

Get the device under test.

Returns
ITestDevice the ITestDevice

getExcludeAnnotations

public  getExcludeAnnotations ()

Returns the current ERROR(/Set) of annotations to exclude.

Returns

getExcludeFilters

public  getExcludeFilters ()

Returns the current ERROR(/Set) of exclude filters.

Returns

getIncludeAnnotations

public  getIncludeAnnotations ()

Returns the current ERROR(/Set) of annotations to include.

Returns

getIncludeFilters

public  getIncludeFilters ()

Returns the current ERROR(/Set) of include filters.

Returns

getRuntimeHint

public long getRuntimeHint ()

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

Returns
long

run

public void run (TestInformation testInfo, 
                ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

Parameters
testInfo TestInformation: The TestInformation object containing useful information to run tests.

listener ITestInvocationListener: the ITestInvocationListener of test results

Throws
DeviceNotAvailableException

setAbi

public void setAbi (IAbi abi)

Parameters
abi IAbi

setBuild

public void setBuild (IBuildInfo buildInfo)

Parameters
buildInfo IBuildInfo

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

setConfiguration

public void setConfiguration (IConfiguration configuration)

Injects the IConfiguration in use.

Parameters
configuration IConfiguration

setDevice

public void setDevice (ITestDevice device)

Inject the device under test.

Parameters
device ITestDevice: the ITestDevice to use

setOptionToLoadedObject

public static void setOptionToLoadedObject (Object testObj, 
                 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 : the list of options formatted as HostTest set-option requires.

setTestInformation

public void setTestInformation (TestInformation testInfo)

Parameters
testInfo TestInformation

split

public  split (Integer shardCount, 
                TestInformation testInfo)

We split by individual by either test class or method.

Parameters
shardCount Integer: the attempted shard count.

testInfo TestInformation: The parent TestInformation

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

Protected methods

createHostTest

protected 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

protected IBuildInfo getBuild ()

Get the build info received by HostTest.

Returns
IBuildInfo the IBuildInfo

getClassLoader

protected ClassLoader getClassLoader ()

Returns the default classloader.

Returns
ClassLoader

getClasses

protected final  getClasses ()

Returns

getJarFile

protected File getJarFile (String jarName, 
                TestInformation testInfo)

Inspect several location where the artifact are usually located for different use cases to find our jar.

Parameters
jarName String

testInfo TestInformation

Returns
File

hasJUnit4Annotation

protected boolean hasJUnit4Annotation (Class<?> classObj)

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

Parameters
classObj Class

Returns
boolean

loadObject

protected Object loadObject (Class<?> classObj)

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

Parameters
classObj Class

Returns
Object

setClassName

protected void setClassName (String className)

Clear then set a class name to be run.

Parameters
className String

shouldTestRun

protected 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.