自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
TF 測試生命週期
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用 Trade Federation 執行的測試生命週期由四個獨立階段組成,這些階段是根據正式定義的介面設計而成。
已定義的介面
TF 中的基本測試實體是「設定」。設定檔是宣告測試生命週期元件的 XML 檔案。
將測試生命週期分開,是為了方便重複使用。採用這種設計後,開發人員可以建立一次測試,整合人員就能建立不同的設定,在不同環境中執行該測試。舉例來說,他們可以建立設定,在本機電腦上執行測試,並將結果轉儲至標準輸出。接著,他們可以建立第二個設定,執行相同的測試,但使用不同的測試叫用事件監聽器,將測試結果儲存在資料庫中。第三個設定可能會設計為從某處的測試實驗室持續執行測試。
在此處,我們要特別指出,設定和指令列引數 (由 Test Runner 提供) 稱為「指令」。當 TF 將指令與 ITestDevice
配對並執行時,後續物件稱為叫用。簡而言之,呼叫包含整個 TF 測試執行作業的整個生命週期。
其他設定元件
階段輸出內容和錯誤
每次叫用都會依序執行各個階段,且各階段都有特定目標。本節將說明各階段的常見輸出內容和錯誤。
建構提供者
這個階段會建立並輸出 IBuildInfo
物件,其中包含設定及執行測試所需的所有檔案參照。
這個階段最常見的錯誤是無法下載或找到要求的檔案。
這個階段發生錯誤會直接回報錯誤,且不會執行任何測試。
目標準備
這個階段會為測試中的目標設定必要狀態。這個階段可視指定測試叫用作業的需要,變更裝置或主機設定。
這個階段常見的錯誤包括無法將裝置設定為特定狀態 (例如閃燈失敗),以及無法找到設定所需的檔案。
這個階段發生錯誤時,系統會執行目標清理作業、回報錯誤,且不會執行任何測試。
測試
這個階段會在先前準備好的目標上執行要求的測試,並回報所有測試執行結果。
這個階段的常見錯誤通常是測試目標無法使用,或是某些錯誤導致測試部分執行。這些錯誤是基礎架構問題,會影響測試執行作業本身,而非單一測試案例的失敗。
這個階段發生錯誤時,測試執行作業會停止,目標清理作業會執行,並回報錯誤及取得部分結果。
結果報表
這個階段會將結果和錯誤回報至已設定的服務 (例如伺服器和本機檔案)。
雖然個別結果回報器可能會發生錯誤,但這些錯誤彼此獨立 (一個回報器不會看到另一個回報器的錯誤)。這些錯誤只會影響個別檢舉者的結果回報,而且您可以在記錄檔中查看這些錯誤。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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 (世界標準時間)。"],[],[],null,["# TF test lifecycle\n\nThe lifecycle of a test executed using Trade Federation is composed of four separate stages,\ndesigned around formally defined interfaces.\n\nDefined interfaces\n------------------\n\n- [Build Provider](/reference/tradefed/com/android/tradefed/build/IBuildProvider): Provides a build to test, downloading appropriate files if necessary.\n- [Target Preparer](/reference/tradefed/com/android/tradefed/targetprep/ITargetPreparer): Prepares the test environment, possibly including software installation and device configuration.\n- [Test](/reference/tradefed/com/android/tradefed/testtype/IRemoteTest): Executes test(s) and gathers test results. This may be any JUnit Test, although our [IRemoteTest](/reference/tradefed/com/android/tradefed/testtype/IRemoteTest) interface is specifically designed to work well in the Trade Federation environment.\n- [Test Invocation Listener (results reporting)](/reference/tradefed/com/android/tradefed/result/ITestInvocationListener): Listens for test results, usually for the purpose of forwarding the test results to a repository or displaying them to the Test Runner.\n\nThe fundamental testing entity in TF is a **Configuration** (config). A config is an XML file\nthat declares the lifecycle components of a test.\n\nThis separation of the test's lifecycle is intended to allow for reuse. Using this design, the\nDeveloper can create a Test once, and then the Integrator can create different Configurations to\nrun that Test in different environments. For example,\nthey could create a Configuration that will run a test on a local machine and dump the result to\nstdout. They could then create a second Configuration that would execute that same test, but use a\ndifferent Test Invocation Listener to store the test results in a database. A third Configuration\nmight be designed run that test continuously from a test lab somewhere.\n\nIt's convenient to note here that a Configuration along with its command-line arguments (as\nprovided by the Test Runner) is known as a **Command** . When TF pairs a Command with an\n`ITestDevice` and executes it, the subsequent object is known as an **Invocation**.\nIn short, an Invocation encompasses a complete TF test execution, across its entire lifecycle.\n\nAdditional configuration components\n-----------------------------------\n\n- [Device Recovery](/reference/tradefed/com/android/tradefed/device/IDeviceRecovery): mechanism to recover device communication if lost.\n- [Logger](/reference/tradefed/com/android/tradefed/log/package-summary): collects tradefed logging data.\n\nStage output and errors\n-----------------------\n\nEach stage of an invocation executes sequentially and has a specific goal. This section describes\nthe usual outputs and errors of each stage.\n\n### Build provider\n\nThis stage creates and outputs an\n[`IBuildInfo`](/reference/tradefed/com/android/tradefed/build/IBuildInfo) object that contains all the required files references to set up and run the tests.\n\nThe most common error at this stage is a failure to download or find the requested files.\n\nAn error at this stage results in directly reporting the error, and no tests being run.\n\n### Target preparation\n\nThis stage sets up the necessary states for the target under tests. This stage can alter the\ndevice or the host setup as needed for the given test invocation.\n\nCommon errors at this stage usually involve failure to setup the device into a given state\n(for example, failed flashing) and failure to find the required files for the setup.\n\nAn error at this stage results in target clean up running, reporting of the error, and no tests\nbeing run.\n\n### Tests\n\nThis stage runs the requested tests on the previously prepared target, and reports all the\ntest execution results.\n\nCommon errors at this stage usually involve the target under test being unavailable or some\nerror causing partial execution of the tests. These errors are infrastructure issues that affect\nthe test execution itself as opposed to a failure of a single test case.\n\nAn error at this stage results in the test execution stopping, the target clean up running,\nreporting the error, and getting partial results.\n\n### Results reporting\n\nThis stage reports the results and errors to the configured services (for example, servers and\nlocal files).\n\nAlthough individual results reporters can have errors, they're isolated from each other\n(one reporter doesn't see errors from another one). These errors affect only an individual\nreporter's own results reporting and the errors can be viewed in the logs."]]