Google is committed to advancing racial equity for Black communities. See how.

Target Preparers

Target Preparers are invoked before the tests in the test level in which they are defined. This allows the setup of any device for tests to run smoothly.

Base interface

The base interface is ITargetPreparer, which allows implementation of a setUp method that will be executed. We recommend implementing our basic abstract class BaseTargetPreparer, which provides a built-in disablement feature to easily disable a preparer.

Cleaner interface

The natural extension of setUp is tearDown and is provided by a different interface ITargetCleaner. That provides the tearDown interface that allows cleaning up anything that was done in setUp after the test execution.

The BaseTargetPreparer class also extends ITargetCleaner.

Recommendations

We recommend each preparer be limited to a single main function, for example installing an APK or running a command. This allows for easier re-use of preparers.

You should also check the list of available preparers before adding a new one to avoid duplicating work. Preparers are available in tools/tradefederation/core/src/com/android/tradefed/targetprep/.

XML configuration

The object tag will be target_preparer, for example:

<target_preparer class="com.android.tradefed.targetprep.InstallApkSetup">
    <option name="install-arg" value="-d"/>
</target_preparer>

Also refer to Suite Setup for context.

Top-level setup

If specified in a top-level setup, the preparer will be run only once for each device. An example is cts-common.xml, which is a top-level setup for Android Compatibility Test Suite (CTS) tests.

Module-level setup

If specified at the module level, the preparer will always be run before that module. An example is backup/AndroidTest.xml, which defines how Tradefed runs the backup CTS module.

Note that while the preparer will run before the module, it will run after any System Status Checkers.