When running device-side tests (instrumentations, UI Automator tests, etc.), host-side collectors might not be ideal because it is difficult to synchronize metric collection to a test running on a device. For example, a screenshot taken asynchronously will most likely miss the wanted screen and be useless.
In order to meet these use cases, a device-side version of our collectors exists and can be used in any 'AndroidJUnitRunner' instrumentation. BaseMetricListener can be implemented in order to automatically report metrics that are collected in a way fully compatible with the Tradefed reporting pipeline.
This library is decoupled from Tradefed itself and can be used without Tradefed.
If you are using the 'AndroidJUnitTest' runner from Tradefed, you can simply specify the following command line option to have your collector running with your tests:
CAUTION: In order for the collector classes to be resolved at runtime, your instrumentation APK will most likely need to statically include them by adding the following to your makefile:
LOCAL_STATIC_JAVA_LIBRARIES += collector-device-lib
When implementing on top of the base class
BaseMetricListener, you may choose
when you would like to collect your metrics during the lifecycle of the
- When a test run starts:
- When a test case starts:
- When a test case ends:
- When a test case fails:
- When a test run ends:
The collection of metrics on the device side is made synchronously to the instrumentation execution itself, and metrics are passed back to the instrumentation results and parsed by Tradefed to be reported as part of the invocation.