DeviceTestCase

public class DeviceTestCase
extends MetricTestCase implements IDeviceTest, IRemoteTest, ITestCollector, ITestFilterReceiver, ITestAnnotationFilterReceiver

java.lang.Object
   ↳ junit.framework.Assert
     ↳ junit.framework.TestCase
       ↳ com.android.tradefed.testtype.MetricTestCase
         ↳ com.android.tradefed.testtype.DeviceTestCase


Helper JUnit test case that provides the IRemoteTest and IDeviceTest services.

This is useful if you want to implement tests that follow the JUnit pattern of defining tests, and still have full support for other tradefed features such as Options

Summary

Fields

protected Set<String> mExcludeAnnotation

The exclude annotations of the test to run

protected Set<String> mExcludeFilters

The exclude filters of the test name to run

protected Set<String> mIncludeAnnotation

The include annotations of the test to run

protected Set<String> mIncludeFilters

The include filters of the test name to run

Public constructors

DeviceTestCase()
DeviceTestCase(String name)

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()
ITestDevice getDevice()

Get the device under test.

void run(TestResult result)

Override parent method to run all test methods if test method to run is null.

void run(ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

void setCollectTestsOnly(boolean shouldCollectTest)

Enables or disables test collection mode

void setDevice(ITestDevice device)

Inject the device under test.

Fields

mExcludeAnnotation

Set<String> mExcludeAnnotation

The exclude annotations of the test to run

mExcludeFilters

Set<String> mExcludeFilters

The exclude filters of the test name to run

mIncludeAnnotation

Set<String> mIncludeAnnotation

The include annotations of the test to run

mIncludeFilters

Set<String> mIncludeFilters

The include filters of the test name to run

Public constructors

DeviceTestCase

DeviceTestCase ()

DeviceTestCase

DeviceTestCase (String name)

Parameters
name String

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

Returns
int

getDevice

ITestDevice getDevice ()

Get the device under test.

Returns
ITestDevice the ITestDevice

run

void run (TestResult result)

Override parent method to run all test methods if test method to run is null.

The JUnit framework only supports running all the tests in a TestCase by wrapping it in a TestSuite. Unfortunately with this mechanism callers can't control the lifecycle of their own test cases, which makes it impossible to do things like have the tradefed configuration framework inject options into a Test Case.

Parameters
result TestResult

run

void run (ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

Parameters
listener ITestInvocationListener: the ITestInvocationListener of test results

Throws
DeviceNotAvailableException

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