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

protected Set<String> mExcludeAnnotation

The exclude annotations of the test to run

mExcludeFilters

protected Set<String> mExcludeFilters

The exclude filters of the test name to run

mIncludeAnnotation

protected Set<String> mIncludeAnnotation

The include annotations of the test to run

mIncludeFilters

protected Set<String> mIncludeFilters

The include filters of the test name to run

Public constructors

DeviceTestCase

public DeviceTestCase ()

DeviceTestCase

public DeviceTestCase (String name)

Parameters
name String

Public methods

addAllExcludeAnnotation

public void addAllExcludeAnnotation (Set<String> notAnnotations)

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

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

countTestCases

public int countTestCases ()

Returns
int

getDevice

public ITestDevice getDevice ()

Get the device under test.

Returns
ITestDevice the ITestDevice

run

public 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

public void run (ITestInvocationListener listener)

Runs the tests, and reports result to the listener.

Parameters
listener ITestInvocationListener: the ITestInvocationListener of test results

Throws
DeviceNotAvailableException

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

Enables or disables test collection mode

setDevice

public void setDevice (ITestDevice device)

Inject the device under test.

Parameters
device ITestDevice: the ITestDevice to use