기기 측 테스트 (예: 계측, UI Automator 테스트)를 실행할 때는 호스트 측 수집기가 적합하지 않을 수도 있습니다. 이는 기기에서 실행되는 테스트에 관한 측정항목 수집을 동기화하기가 어렵기 때문입니다. 예를 들어 비동기식으로 캡처한 스크린샷은 원하는 화면을 놓칠 가능성이 높으므로 소용이 없습니다.
이러한 사용 사례를 충족하기 위해 Google 수집기의 기기 측 버전이 존재하며, 모든 AndroidJUnitRunner 계측에 이를 사용할 수 있습니다.
BaseMetricListener를 구현하면 Tradefed 보고 파이프라인과 온전히 호환되는 방식으로 수집된 측정항목을 자동으로 보고할 수 있습니다.
이 라이브러리는 Tradefed 자체에서 분리되며 Tradefed 없이 사용할 수 있습니다.
Tradefed의 AndroidJUnitTest 실행기를 사용 중인 경우에는 다음과 같은 명령줄 옵션을 지정하여 수집기가 테스트와 함께 실행되도록 하기만 하면 됩니다.
기본 클래스 BaseMetricListener 외에 추가로 구현하는 경우 계측 수명 주기 동안 어느 시점에 측정항목을 수집하고 싶은지 선택할 수 있습니다.
테스트 실행 시작 시: onTestRunStart
테스트 사례 시작 시: onTestStart
테스트 사례 종료 시: onTestEnd
테스트 사례 실패 시: onTestFail
테스트 실행 종료 시: onTestRunEnd
상호작용
기기 측의 측정항목 수집은 계측 실행 자체에 동기식으로 이루어지며 측정항목은 다시 계측 결과로 전달되고 Tradefed에 의해 파싱되어 호출의 일부로 보고됩니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Device-side metrics collectors\n\nWhen running device-side tests (for example, instrumentations, UI Automator\ntests), host-side collectors might not be ideal because it's difficult to\nsynchronize metric collection to a test running on a device. For example, a\nscreenshot taken asynchronously is likely to miss the wanted screen and be\nuseless.\n\nTo meet these use cases, a device-side version of our collectors exists\nand can be used in any `AndroidJUnitRunner` instrumentation.\n[`BaseMetricListener`](https://android.googlesource.com/platform/platform_testing/+/refs/heads/android16-release/libraries/device-collectors/src/main/java/android/device/collectors/BaseMetricListener.java)\ncan be implemented to automatically report metrics that are collected\nin a way fully compatible with the Tradefed reporting pipeline.\n\nThis library is decoupled from Tradefed itself and can be used without Tradefed.\n\nIf you're using the [`AndroidJUnitTest`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/test_framework/com/android/tradefed/testtype/AndroidJUnitTest.java)\nrunner from Tradefed, you can specify the following command line option\nto have your collector running with your tests: \n\n --device-listeners android.device.collectors.ScreenshotListener\n\n**Caution:** In order for the collector classes to be resolved at runtime, your instrumentation APK needs to statically include them by adding the following to your makefile: \n\n LOCAL_STATIC_JAVA_LIBRARIES += collector-device-lib\n\nImplementation\n--------------\n\nWhen implementing on top of the base class `BaseMetricListener`, you can choose\nwhen you would like to collect your metrics during the lifecycle of the\ninstrumentation:\n\n- When a test run starts: `onTestRunStart`\n- When a test case starts: `onTestStart`\n- When a test case ends: `onTestEnd`\n- When a test case fails: `onTestFail`\n- When a test run ends: `onTestRunEnd`\n\nInteraction\n-----------\n\nThe collection of metrics on the device side is made synchronously to the\ninstrumentation execution itself, and metrics are passed back to the\ninstrumentation results and parsed by Tradefed to be reported as part of the\ninvocation."]]