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

Include Unit Tests

This section explains how to run Trade Federation tests after making a change to the project. This includes:

  • Where to add the new unit test classes
  • Running unit tests in Eclipse and outside the Eclipse IDE
  • Running the functional tests
  • Running some of TF presubmit validation locally

Add unit tests

In the Android Open Source Project (AOSP), add the unit tests class in: tools/tradefederation/core/tests/src/com/android/tradefed/

IMPORTANT: Adding your new unit test classes to these locations will result in them automatically running in presubmit without additional setup.

Run unit tests

All the AOSP unit tests and functional tests for Trade Federation are located in the tools/tradefederation/core/tests project.

Inside Eclipse, to run an individual unit test, simply right-click the test and select Run As > JUnit. To run all unit tests, run the suite.

You can also start the unit test from the command line in the Tradefed source tree after building, like so: tools/tradefederation/core/tests/

Unit tests can be executed standalone, but functional tests should be executed by using Trade Federation itself; they require an Android device. All functional tests should follow the naming convention *FuncTest.

Check unit tests results

When running, the unit tests are exercising all parts of the test harness including some error conditions. It will print verbose output to the console, including stack traces.

The final summary of the results will indicate if a failure occured or not.

Example final summary in the console:

12:55:02 ========== Result Summary ==========
Results summary for test-tag 'TFUnitTests': 3355 Tests [3355 Passed]

All tests are maintained to pass, so if any failure occurs on your local change please ensure the tests are fixed.

Run functional tests

To run a functional test from Eclipse:

  1. Ensure a device is connected to the host and that adb and if necessary fastboot are in Eclipse's PATH. The easiest way to do this is to launch Eclipse from a shell setup with the proper PATH.
  2. Create a Java application. Run configuration via Run > Run configurations.
  3. Set project to google-tradefederation-tests and the main class to
  4. Provide the following command line arguments in the Arguments tab: host --class <full path of test class to run>
  5. Click Run.

To run functional tests outside Eclipse.

  1. Build Trade Federation.
  2. Connect an Android device to the host.
  3. Run tools/tradefederation/core/tests/
  4. Optionally, choose the device by appending --serial <serial no> as it appears in the output of adb devices.

Running TF presubmit tests against local changes

If you want to run in a similar way as the TF presubmit, use this:


This will trigger all the TF presubmit tests against your locally built TF to help you validate that your change is not breaking any tests.

TF presubmit tests are a superset of the unit tests above, but it is slower to run them. So it is recommended to run the unit tests during development for quicker validation and to run the presubmits before uploading the CL.