This page tells you how to write a host-side test that doesn’t require a device, such as a test that runs on a Linux GCE instance. (For details about writing a host-driven test that requires a device, refer to Write a Host-driven Test in Trade Federation.)
Host-side test types
You can run several types of host-side tests through Trade Federation (TF).
Native (gtest) tests
Create Native tests (gtests) to test a platform. If the test doesn’t require a device, run it on a host; the test will run much faster that way. To configure such tests to run on a test host, use the TF runner HostGTest.
This is a sample TradeFed test configuration:
<configuration description="Runs hello_world_test."> <option name="null-device" value="true" /> <test class="com.android.tradefed.testtype.HostGTest" > <option name="module-name" value="hello_world_test" /> </test> </configuration>
The test configuration runs a gtest test (hello_world_test) on a host. The example test config can be auto-generated. Unless your test needs a special setup or cleanup, you can rely on auto test-config generation to create proper TF test configurations.
To configure a host-side gtest and enable auto test- config generation, set
Android.bp, as in hello_world_test.
For more information about writing a native test, see Adding a New Native Test Example.
JAR (Java) host tests
JAR host tests, such as JUnit, are tests that don’t need to run on a device, and that provide code coverage of your Java project. Such tests can be configured to run on a test host by using the runner HostTest.
Sample TradeFed test configuration:
<configuration description="Executes HelloWorldHostTest"> <test class="com.android.tradefed.testtype.HostTest" > <option name="jar" value="HelloWorldHostTest.jar" /> </test> </configuration>
The test configuration runs a host-side JUnit test of HelloWorldHostTest. Note that the above test configuration can be auto-generated. Unless your test needs special setup or cleanup, rely on the auto test-config generation to create proper TradeFed test configuration.
For more details about how to write a JAR host test, refer to the JAR (Java) Host Tests page.
Isolated Java Host Tests
Deviceless Java tests can be run in an isolation environment with a slight performance cost. However, there are a couple of major considerations to be made before choosing to use this environment.
- Tradefed supports only JUnit tests in the isolation environment.
- Only statically linked dependencies are supported. No dependencies declared
libare included on the classpath.
- The isolation runner only puts the shim runner and your test jar on the classpath.
- There is some amount of fixed overhead per test run executed with this runner.
- This option is not yet available for autogeneration; thus, you will need to write an
AndroidTest.xmlfile for your test.
Sample Tradefed test configuration (isolated)
<configuration description="Executes HelloWorldIsolatedHostTest"> <test class="com.android.tradefed.testtype.HostTest" > <option name="jar" value="HelloWorldHostTest.jar" /> </test> </configuration>
Sample TradeFed test configuration
<configuration description="Config to run atest unittests"> <test class="com.android.tradefed.testtype.python.PythonBinaryHostTest" > <option name="par-file-name" value="atest_unittests" /> <option name="test-timeout" value="2m" /> </test> </configuration>
Test suite setting
For the host-side test to be accessible by TF for a given build, set the
`test_suites` setting to
With this setting, the test is packaged to