設定套裝組合

在 Tradefed 中,「套件」是指在通用測試執行器下執行多項測試的設定,可驅動整體執行作業。

在 Tradefed 中,套件是由 ITestSuite 類別驅動,可讓測試獨立新增及移除,不受執行方式影響。

定義

  • 套件:設定為在類似的頂層設定下執行的測試模組集,可在單一叫用下回報結果。
  • 頂層設定:在執行任何測試模組前,套用至裝置的設定。
  • 主要設定:套件層級的 Tradefed XML 設定,用於說明應執行哪些模組,以及應使用哪些頂層設定
  • 模組層級設定:在執行模組前,將設定套用至裝置。這也稱為模組專屬設定
  • 模組設定:指描述模組的 AndroidTest.xml Tradefed XML 設定,以及應完成的模組層級設定
  • 模組:測試單元,由設定步驟 (模組層級設定)、測試執行步驟和拆除步驟組成。
  • 模組內重試:由模組內的架構自動重試。
  • 套件重試:完整重新執行先前失敗的套件測試。

ITestSuite 結構

ITestSuite 在 Tradefed 中是指驅動套件執行的常見基本類別。所有主要測試套件 (特別是 Android Compatibility Test Suite (CTS)Android Vendor Test Suite (VTS)) 都會共用這個架構,確保所有套件的執行體驗一致。

我們有時會將 ITestSuite 稱為「套件執行器」

執行時,套件執行器會按照下列步驟操作:

  1. 載入模組的設定,並決定要執行的設定集。
  2. 執行每個模組:

    1. 執行模組層級設定。
    2. 執行模組測試。
    3. 執行模組層級的拆解作業。
  3. 回報結果。

頂層設定

從 Tradefed 的角度來看,ITestSuite 只是另一項測試。這項測試很複雜,但仍與其他 IRemoteTest 一樣。因此,在 Tradefed 設定中指定套件執行器時,Tradefed 會遵循一般設定模式:執行 build_providertarget_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

上述指令會使用 framework 做為 component 中繼資料,執行所有模組。

完整 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] 與基本 CtsGestureTestCases) 顯示結果。