Follow these steps to set up Tradefed using Eclipse.
Create a separate workspace to develop Trade Federation, do not reuse a workspace already employed for Android-device development.
If needed, you can download the Eclipse IDE for Java developers from: eclipse.org/downloads
- Run make once from the command line. This will build external libraries depended by the projects below.
- Set TRADEFED_ROOT classpath variable in
Window > Preferences > Java > Build Path> Classpath Variablesand point it to your tradefed source root
- Set TRADEFED_ROOT path variable in
Window > Preferences > General > Workspace > Linked Resourcesand point it to your tradefed source root
File > Import...-> General > Existing Projects into workspace"wizard to bring in these open source Java projects under the following paths:
prebuilts/misc/common/ddmlib\* tools/loganalysis tools/loganalysis/tests tools/tradefederation/core tools/tradefederation/core/tests tools/tradefederation/contrib tools/tradefederation/core/remote platform_testing/libraries/longevity platform_testing/libraries/annotations platform_testing/libraries/composer
Optionally, if you want to see
ddmlibsource code, attach the source code from an unbundled tools branch, such as /platform/tools/base/tools_r22/ddmlib/src/main/java/com/android/ddmlib/IDevice.java.
Optionally, if you also want the CTS harness projects loaded, import:
test/suite_harness/common/util test/suite_harness/common/host-side/util test/suite_harness/common/host-side/tradefed
NOTE: Requisite files live within
development/ide/eclipse in the full platform
source tree. So you will need to check out a platform branch such as
to get these files:
Use preference files in Eclipse to automatically set the formatter to the Android style guide. To do this in Studio:
- Go to Window > Preferences > Java > Code Style.
- Under Formatter, import the file
- Under Organize > Imports, import the file
Remove trailing whitespaces
To force Eclipse to remove all trailing whitespace:
- Go to Window > Preferences -> Java -> Editor -> Save Actions.
- Then Additional Actions -> Configure -> Code > Organizing tab -> Formatter.
- Check Remove Trailing Whitespace.
- Click Apply and Close.
Check code style
When submitting a changelist, an automatic preupload hook will run to check your
This helps formatting your code to the common standard.
If you want to run TF code through a debugger in Eclipse, it is recommended you first create a unit test for the code in question as this will be the simplest and fastest way to exercise the functionalilty.
To debug a TF unit test, simply right-click on it and select Debug As > JUnit test.
To debug a TF functional test, follow the instructions in the previous section for running a functional test but use the Run > Debug configurations menu.
To debug the TF program itself, when running any configuration, follow the
instructions in the previous section for running a functional test but provide
the command line arguments for the configuration you wish to run in step 4. So
to debug the 'instrument' configuration, go to the Run > Debug configuration
menu and set the Arguments tab in the Eclipse debug configuration to
-- package <package to run> instrument.
Remote debug with Eclipse
Follow these steps to remotely debug a tradefed session started from
tradefed.sh command line:
- Start tradefed.sh with the debug flag:
- Wait until you see this prompt from the JVM:
Listening for transport dt_socket at address: 10088This means the JVM is waiting for debugger to attach at port
- Attach with Eclipse's remote debugging from main menu: Select Run > Debug Configurations....
- In the pop-up dialog, select Remote Java Application from the left menu.
- Click the New launch configuration icon on the action bar.
- Name the configuration as you desire and select tradefederation as the project.
- Populate the port using the address provided earlier.
- Switch to the Source tab and add the projects tradefederation and google-tradefed to the Source Lookup Path.
- Click Debug to start the debugging session.
The debugger attaches to the listening JVM process, and the terminal running
tradefed.sh shows the
To step through your code in debug mode, set a break point in Eclipse and invoke
your Tradefed command (i.e.
run <test>) in the terminal. To debug anything
during TF startup, you can set the break point first and then attach the Eclipse
TIP: To use an alternative port, add
TF_DEBUG_PORT=nnnto the command in step 1
above. You can even use this in production environment if you have mysterious
hang bugs to investigate: change
start with debug flag. The JVM won't wait for debugger to attach, but you can do
so at any time as long as the process is still running.
Remote debug using JDB
To use the Java Debugger JDB, follow steps resembling those for Eclipse:
tradefed.shwith the debug flag:
- Wait until you see the prompt from JVM:
Listening for transport dt_socket at address: 10088.
jdb. For example, from croot run:
jdb -attach 10088 \ -sourcepath tools/tradefederation/core/src:vendor/google_tradefederation/core/src
Wait for the connection and debug away! Run
man jdbfor more help.
Examine code coverage
- Install the Eclemma plugin.
- Go to Help > Install New Software and point the wizard to: http://update.eclemma.org/
- Once installed, select the Coverage As > JUnit test option to conduct a code coverage run.