自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
收集失敗記錄的自動化功能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在偵錯測試時,您一律需要一組記錄,才能取得失敗和測試裝置的基本資訊。來源包括:Logcat、Tradefed 主機記錄、螢幕截圖等。
為了讓任何測試編寫者都能輕鬆取得這些記錄,Tradefed 提供了內建機制,協助收集這些記錄。
設定
如要自動收集失敗時的部分記錄,您可以將下列選項加入 Tradefed 指令列:
--auto-collect LOGCAT_ON_FAILURE
or
--auto-collect SCREENSHOT_ON_FAILURE
如要查看可能值的完整清單,請查看 AutoLogCollector
為方便起見,logcat 和螢幕截圖各有一個直接標記:
--logcat-on-failure
and
--screenshot-on-failure
套件模組 (AndroidTest.xml) 的注意事項
模組無法直接在 AndroidTest.xml
中指定此選項,但可以改用模組控制器。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Automated log on failure collection\n\nWhen debugging tests, a set of logs is always needed to get a basic picture of\nthe failure and the device under test.\nSources include: Logcat, Tradefed host log, screenshot, etc.\n\nIn order to make it generic and painless for any test writer to get those logs,\nTradefed has a built-in mechanism to help collecting them.\n\nConfiguration\n-------------\n\nTo automatically collect some logs on failure, you can add the following option\nto your Tradefed command line: \n\n --auto-collect LOGCAT_ON_FAILURE\n or\n --auto-collect SCREENSHOT_ON_FAILURE\n\nTo see the full list of possible values, checkout\n[AutoLogCollector](https://android.googlesource.com/platform/tools/tradefederation/+/android16-release/src/com/android/tradefed/device/metric/AutoLogCollector.java)\n\nFor convenience, logcat and screenshot each have a direct flag: \n\n --logcat-on-failure\n and\n --screenshot-on-failure\n\nNote on suite modules (AndroidTest.xml)\n---------------------------------------\n\nModules cannot direcly specify this option in the `AndroidTest.xml`, but they\ncan use a [module controller](/docs/core/tests/tradefed/testing/through-suite/module-controller)\ninstead."]]