AndroidJUnitTest

public class AndroidJUnitTest
extends InstrumentationTest implements IRuntimeHintProvider, ITestFileFilterReceiver, ITestFilterReceiver, ITestAnnotationFilterReceiver, IShardableTest, IStrictShardableTest

java.lang.Object
   ↳ com.android.tradefed.testtype.InstrumentationTest
     ↳ com.android.tradefed.testtype.AndroidJUnitTest


A Test that runs an instrumentation test package on given device using the android.support.test.runner.AndroidJUnitRunner.

Summary

Constants

String AJUR

String NEW_RUN_LISTENER_ORDER_KEY

instrumentation test runner argument used to enable the new RunListener order on device side.

Public constructors

AndroidJUnitTest()

Public methods

void addAllExcludeAnnotation(Set<String> excludeAnnotations)

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 excludeAnnotation)

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.

long getRuntimeHint()

Return the expected runtime of the test in milliseconds.

IRemoteTest getTestShard(int shardCount, int shardIndex)

Returns a IRemoteTest for a single shard.

boolean isClassOrMethod(String filter)

Return if a string is the name of a Class or a Method.

void run(ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

void setExcludeTestFile(File testFile)

Sets the test file of excludes.

void setIncludeTestFile(File testFile)

Sets the test file of includes.

Collection<IRemoteTest> split(int shardCount)

Alternative version of split() which also provides the shardCount that is attempted to be run.

Protected methods

void setRunnerArgs(IRemoteAndroidTestRunner runner)

Constants

AJUR

protected static final String AJUR

Constant Value: "android.support.test.runner.AndroidJUnitRunner"

NEW_RUN_LISTENER_ORDER_KEY

public static final String NEW_RUN_LISTENER_ORDER_KEY

instrumentation test runner argument used to enable the new RunListener order on device side.

Constant Value: "newRunListenerMode"

Public constructors

AndroidJUnitTest

public AndroidJUnitTest ()

Public methods

addAllExcludeAnnotation

public void addAllExcludeAnnotation (Set<String> excludeAnnotations)

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

Parameters
excludeAnnotations Set

addAllExcludeFilters

public void addAllExcludeFilters (Set<String> filters)

Adds the Set of filters of which tests to exclude.

Parameters
filters Set

addAllIncludeAnnotation

public void addAllIncludeAnnotation (Set<String> annotations)

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

Parameters
annotations Set

addAllIncludeFilters

public void addAllIncludeFilters (Set<String> filters)

Adds the Set of filters of which tests to include.

Parameters
filters Set

addExcludeAnnotation

public void addExcludeAnnotation (String excludeAnnotation)

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

Parameters
excludeAnnotation 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

getRuntimeHint

public long getRuntimeHint ()

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

Returns
long

getTestShard

public 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

isClassOrMethod

public boolean isClassOrMethod (String filter)

Return if a string is the name of a Class or a Method.

Parameters
filter String

Returns
boolean

run

public void run (ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

Parameters
listener ITestInvocationListener: the ITestInvocationListener of test results

Throws
DeviceNotAvailableException

setExcludeTestFile

public void setExcludeTestFile (File testFile)

Sets the test file of excludes. Does not ensure that testFile exists or is a file.

Parameters
testFile File

setIncludeTestFile

public void setIncludeTestFile (File testFile)

Sets the test file of includes. Does not ensure that testFile exists or is a file.

Parameters
testFile File

split

public Collection<IRemoteTest> split (int shardCount)

Alternative version of split() which also provides the shardCount that is attempted to be run. This is useful for some test runner that cannot arbitrarly decide sometimes.

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

setRunnerArgs

protected void setRunnerArgs (IRemoteAndroidTestRunner runner)

Parameters
runner IRemoteAndroidTestRunner