自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
設定套裝組合
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Tradefed 中的「套件」是指在驅動整體執行作業的通用測試執行程式下執行多個測試的設定。
在 Tradefed 中,套件會透過 ITestSuite
類別驅動,讓您可以新增及移除測試,而無須考量測試的執行方式。
定義
- 套件:一組測試模組,已設定為在類似的頂層設定下執行,以便在單一叫用中回報結果。
- 頂層設定:在執行任何測試模組前,先對裝置套用設定。
- 主要設定:套件層級的 Tradefed XML 設定,用於說明應執行哪些模組,以及應使用哪些頂層設定。
- 模組層級設定:在執行模組前,將設定套用至裝置。這也稱為模組專屬設定。
- 模組設定:指的是
AndroidTest.xml
Tradefed XML 設定,用於說明模組,以及應執行哪些模組層級設定。
- 模組:由設定步驟 (模組層級設定)、測試執行步驟和解除安裝步驟組成的測試單元。
- 模組內重試:由模組內的測試套件自動重試。
- 套件重試:重新執行套件先前失敗的測試。
ITestSuite 結構
Tradefed 中的 ITestSuite
是指執行套件的通用基礎類別。所有主要測試套件都會共用此檔案,特別是 Android 相容性測試套件 (CTS) 和 Android 供應商測試套件 (VTS),以確保所有套件都能提供一致的執行體驗。
我們有時會將 ITestSuite 稱為套件執行程式。
套件執行程式執行時會遵循下列步驟:
- 載入模組的設定,並決定要執行哪個集合。
執行每個模組:
- 執行模組層級設定。
- 執行模組測試。
- 執行模組層級拆解作業。
回報結果。
頂層設定
從 Tradefed 的角度來看,ITestSuite
只是另一項測試。這項測試雖然複雜,但仍與任何其他 IRemoteTest
一樣,只是測試而已。因此,在 Tradefed 設定中指定套裝組合執行程式時,Tradefed 會遵循設定的一般模式:執行 build_provider
、target_preparer
、測試 (在本例中為套裝組合) 和 target_cleaner
。
在 Tradefed 設定中,含有 ITestSuite
的這個序列是頂層設定。
例子:
<configuration description="Common config for Compatibility suites">
<build_provider class="com.android.compatibility.common.tradefed.build.CompatibilityBuildProvider" />
<!-- Setup applied before the suite: so everything running in the suite will
have this setup beforehand -->
<target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
<option name="run-command" value="settings put global package_verifier_enable 0" />
<option name="teardown-command" value="settings put global package_verifier_enable 1"/>
</target_preparer>
<!-- Our ITestSuite implementation -->
<test class="com.android.compatibility.common.tradefed.testtype.suite.CompatibilityTestSuite" />
<result_reporter class="com.android.compatibility.common.tradefed.result.ConsoleReporter" />
</configuration>
我們稱測試模組 AndroidTest.xml
中指定的額外資訊為「模組中繼資料」。您可以使用這項中繼資料指定模組的其他資訊,並使用中繼資料篩選模組。
中繼資料範例:
<option name="config-descriptor:metadata" key="component" value="framework" />
<option name="config-descriptor:metadata" key="parameter" value="instant_app" />
中繼資料篩選器範例:
--module-metadata-include-filter component=framework
上述指令會以架構做為元件中繼資料,執行所有模組。
完整 AndroidTest.xml
範例:
<configuration description="Config for CTS Gesture test cases">
<option name="test-suite-tag" value="cts" />
<!-- Metadata -->
<option name="config-descriptor:metadata" key="component" value="framework" />
<option name="config-descriptor:metadata" key="parameter" value="instant_app" />
<!-- End: metadata -->
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
<option name="test-file-name" value="CtsGestureTestCases.apk" />
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="android.gesture.cts" />
<option name="runtime-hint" value="10m50s" />
</test>
</configuration>
參數化模組
特殊中繼資料類型為 parameter
。
<option name="config-descriptor:metadata" key="parameter" value="instant_app" />
這項中繼資料指定模組必須以不同的模式執行,例如以即時應用程式模式執行,而非標準應用程式模式。
所有可能的模式或參數皆由 ModuleParameters
說明,並在 ModuleParametersHelper
中提供相關聯的處理常式,讓您變更模組設定,以便在特定模式下執行。
舉例來說,即時應用程式模式會強制以即時模式安裝 APK。
如要啟用參數化,指令列必須使用下列項目:
--enable-parameterized-modules
您也可以使用下列方式執行單一模式:
--enable-parameterized-modules --module-parameter <Mode>
--enable-parameterized-modules --module-parameter INSTANT_APP
模組的參數化版本執行時,會在參數化模組名稱下回報結果,例如 CtsGestureTestCases[instant]
與 base CtsGestureTestCases
。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Set up suites\n\nA *suite* in Tradefed refers to a setup where several tests are running under a\ncommon test runner that drives the overall execution.\n\nIn Tradefed, suites are driven through the\n[`ITestSuite`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/testtype/suite/ITestSuite.java)\nclass, which lets tests be added and removed independently of how they are\nrun.\n\nDefinitions\n-----------\n\n- Suite: Set of *test modules* configured to run under a similar *top-level\n setup* to report their results under a single invocation.\n- Top-level setup: Setup applied to the devices before running any of the test modules.\n- Main configuration: The suite-level Tradefed XML configuration that describes which modules should run and which *top-level setup* should be used.\n- Module-level setup: Setup applied to the devices right before running the module. These are also known as *module-specific setups*.\n- Module configuration: Refers to the `AndroidTest.xml` Tradefed XML configuration that describes the modules and which *module-level setup* should be done.\n- Module: Test unit composed of a setup step (*module-level setup*), a test execution step and a tear down step.\n- Intra-module retry: Automatic retry done by the harness inside the module.\n- Suite retry: Full rerun of the suite's previously failed tests.\n\nITestSuite structure\n--------------------\n\n[`ITestSuite`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/testtype/suite/ITestSuite.java)\nin Tradefed refers to the common base class driving a suite execution. It's\nshared by all major test suites, specifically the [Android Compatibility Test\nSuite (CTS)](/docs/compatibility/cts) and [Android Vendor Test Suite\n(VTS)](/docs/compatibility/vts), and ensures a consistent execution experience\nacross all suites.\n\nWe sometimes refer to *ITestSuite* as the *suite runner*.\n\nThe suite runner follows these steps when executing:\n\n1. Load the module's configuration and determine which set should run.\n2. Run each module:\n\n 1. Run module-level setup.\n 2. Run module tests.\n 3. Run module-level tear down.\n3. Report the results.\n\nTop-level setup\n---------------\n\nFrom a Tradefed point of view, `ITestSuite` is just another test. It's a complex\none but is still just a test like any other `IRemoteTest`. So when specifying\nthe suite runner in a Tradefed configuration, Tradefed follows the usual\npattern of the configuration: running `build_provider`, `target_preparer`, test\n(our suite in this case), and `target_cleaner`.\n\nThis sequence in the Tradefed configuration containing the `ITestSuite` is the\ntop-level setup.\n\nExample: \n\n \u003cconfiguration description=\"Common config for Compatibility suites\"\u003e\n\n \u003cbuild_provider class=\"com.android.compatibility.common.tradefed.build.CompatibilityBuildProvider\" /\u003e\n \u003c!-- Setup applied before the suite: so everything running in the suite will\n have this setup beforehand --\u003e\n \u003ctarget_preparer class=\"com.android.tradefed.targetprep.RunCommandTargetPreparer\"\u003e\n \u003coption name=\"run-command\" value=\"settings put global package_verifier_enable 0\" /\u003e\n \u003coption name=\"teardown-command\" value=\"settings put global package_verifier_enable 1\"/\u003e\n \u003c/target_preparer\u003e\n\n \u003c!-- Our ITestSuite implementation --\u003e\n \u003ctest class=\"com.android.compatibility.common.tradefed.testtype.suite.CompatibilityTestSuite\" /\u003e\n\n \u003cresult_reporter class=\"com.android.compatibility.common.tradefed.result.ConsoleReporter\" /\u003e\n \u003c/configuration\u003e\n\nModule metadata\n---------------\n\nWe call *module metadata* extra information specified in the test module\n`AndroidTest.xml`. This metadata lets you specify additional information about\nthe module, and modules can be filtered using the metadata.\n\nExample metadata: \n\n \u003coption name=\"config-descriptor:metadata\" key=\"component\" value=\"framework\" /\u003e\n \u003coption name=\"config-descriptor:metadata\" key=\"parameter\" value=\"instant_app\" /\u003e\n\nExample filter on metadata: \n\n --module-metadata-include-filter component=framework\n\nThe above would run all the modules with a *framework* as *component* metadata.\n\nFull `AndroidTest.xml` example: \n\n \u003cconfiguration description=\"Config for CTS Gesture test cases\"\u003e\n \u003coption name=\"test-suite-tag\" value=\"cts\" /\u003e\n \u003c!-- Metadata --\u003e\n \u003coption name=\"config-descriptor:metadata\" key=\"component\" value=\"framework\" /\u003e\n \u003coption name=\"config-descriptor:metadata\" key=\"parameter\" value=\"instant_app\" /\u003e\n \u003c!-- End: metadata --\u003e\n \u003ctarget_preparer class=\"com.android.tradefed.targetprep.suite.SuiteApkInstaller\"\u003e\n \u003coption name=\"cleanup-apks\" value=\"true\" /\u003e\n \u003coption name=\"test-file-name\" value=\"CtsGestureTestCases.apk\" /\u003e\n \u003c/target_preparer\u003e\n \u003ctest class=\"com.android.tradefed.testtype.AndroidJUnitTest\" \u003e\n \u003coption name=\"package\" value=\"android.gesture.cts\" /\u003e\n \u003coption name=\"runtime-hint\" value=\"10m50s\" /\u003e\n \u003c/test\u003e\n \u003c/configuration\u003e\n\nParameterized module\n--------------------\n\nA special metadata type is `parameter`. \n\n \u003coption name=\"config-descriptor:metadata\" key=\"parameter\" value=\"instant_app\" /\u003e\n\nThis metadata specifies that the module needs to be executed in a different\n*mode*, for example as an instant app, instead of a standard app mode.\n\nAll the possible modes or parameters are described by\n[`ModuleParameters`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/testtype/suite/params/ModuleParameters.java)\nand have an associated handler in\n[`ModuleParametersHelper`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/testtype/suite/params/ModuleParametersHelper.java)\nthat lets you change the module setup to execute in the particular mode.\n\nFor example, the instant app mode forces the APK installation as instant\nmode.\n\nIn order for the parameterization to occur, the command line needs to enable it\nwith: \n\n --enable-parameterized-modules\n\nIt's also possible to run a single given mode with: \n\n --enable-parameterized-modules --module-parameter \u003cMode\u003e\n\n --enable-parameterized-modules --module-parameter INSTANT_APP\n\nWhen a parameterized version of a module runs, it reports its results under\na parameterized module name, for example `CtsGestureTestCases[instant]` versus\nbase `CtsGestureTestCases`."]]