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.
The base interface is
which allows implementation of a
setUp method that will be executed. We
recommend implementing our basic abstract class
which provides a built-in disablement feature to easily disable a preparer.
The natural extension of
tearDown and is provided by a different
ITargetCleaner. That provides the
that allows cleaning up anything that was done in
setUp after the test
BaseTargetPreparer class also extends
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/.
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.
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.
If specified at the module level, the preparer will always be run before that
module. An example is
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.