AndroidTest.xml結構

模組配置的整體結構遵循與常規 Tradefed XML 配置類似的模式,但由於它們作為套件的一部分運作而存在一些限制。

允許的標籤列表

AndroidTest.xml或更廣泛的模組配置只能包含以下 XML 標籤: target_preparermulti_target_preparertestmetrics_collector

儘管該清單看起來具有限制性,但它允許您精確定義測試模組設定需求和要執行的測試。

注意:如果您需要回顧不同標籤,請參閱Tradefed XML 設定

如果試圖從模組配置內部運行,諸如build_providerresult_reporter之類的物件將引發ConfigurationException 。這是為了避免期望這些物件實際從模組內執行某些任務。

模組配置範例

<configuration description="Config for CTS Gesture test cases">
    <option name="test-suite-tag" value="cts" />
    <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>

此配置描述了一個測試,需要安裝CtsGestureTestCases.apk並將針對android.gesture.cts套件執行檢測。

包含標籤<include><template-include>

不鼓勵在模組配置中使用<include><template-include> 。不保證它們能夠按預期工作。

metrics_collector 標籤的特殊情況

允許使用metrics_collector但僅限於FilePullerLogCollector類,以便指定要為模組拉取和記錄的給定檔案或目錄。如果您將日誌留在特定位置並希望自動恢復它們,這非常有用。

設定範例:

<configuration description="Config for CTS UI Rendering test cases">
    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true" />
        <option name="test-file-name" value="CtsUiRenderingTestCases.apk" />
    </target_preparer>
    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
        <option name="package" value="android.uirendering.cts" />
        <option name="runtime-hint" value="11m55s" />
        <option name="runner" value="android.uirendering.cts.runner.UiRenderingRunner" />
        <option name="isolated-storage" value="false" />
    </test>

    <!-- Collect the files in the dump directory for debugging -->
    <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
        <option name="directory-keys" value="/sdcard/UiRenderingCaptures" />
        <option name="collect-on-run-ended-only" value="true" />
    </metrics_collector>
</configuration>

建置資訊或下載怎麼樣?

允許的標籤的定義可能會給人錯誤的印象,即模組不會取得任何建置資訊。這不是真的

建置資訊由套件層級設定提供,並將由套件的所有模組共用。這允許套件的單個頂級設置,以便運行套件的所有模組部分。

例如,不是每個相容性測試套件 (CTS)模組單獨查詢設備資訊、類型等,而是 CTS 套件層級設定 ( cts.xml ) 執行一次,每個模組將在請求時接收該資訊。

為了讓模組中的物件接收建置訊息,它們需要執行與常規 Tradefed 配置中相同的操作:實作IBuildReceiver介面以接收IBuildInfo 。有關更多詳細信息,請參閱使用設備進行測試

元資料字段

大量的測試模組包含一些metadata規範,每個元資料規範都有獨特的目標。

例子:

  <option name="config-descriptor:metadata" key="component" value="framework" />
  <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
  <option name="config-descriptor:metadata" key="parameter" value="multi_abi" />
  <option name="config-descriptor:metadata" key="parameter" value="secondary_user" />

成分

component元資料描述了模組打算測試的一般 Android 元件。它對測試執行沒有任何直接影響;它主要用於組織目的。

CtsConfigLoadingTest中提供了 CTS 允許的元件的最新清單。如果將不存在的元件新增至 CTS 模組,則此測試會在預先提交中失敗。

您可以使用module-metadata-include-filtermodule-metadata-exclude-filter根據組件過濾套件運行。

例子:

  --module-metadata-include-filter component framework

本範例僅運行使用framework組件註解的測試模組。

範圍

parameter元資料是資訊性的並影響測試執行。它指定測試模組適用於哪種Android模式。在這種情況下,模式僅限於進階 Android 模式,例如instant appssecondary usersdifferent abis

在套件運行期間,如果該模式適用於測試,則會根據該模式建立測試模組的多個變體。每個變體都運行類似的測試,但在不同的模式下。

  • instant_app :建立將 APK 安裝為即時應用程式的測試變體。
  • multi_abi :為裝置支援的每個 ABI 建立測試的變體。
  • secondary_user :建立安裝 APK 並以輔助使用者身分執行測試的測試變體。

性能測試模組的指標收集和後處理

對於效能測試模組,允許使用模組級的metrics_collectormetric_post_processor ,因為它們對於效能測試至關重要。模組級度量收集器和後處理器可以是特定於模組的。不建議在頂層和模組級都指定後處理器。

效能測試模組配置必須包含具有值performance test-type數據,例如: xml <option name="config-descriptor:metadata" key="test-type" value="performance" />如果沒有此選項,如果測試config 包含FilePullerLogCollector以外的metric_collector或任何metric_post_processor ,測試在預先提交中失敗。

效能測試模組配置範例:

<configuration description="Runs sample performance test.">
    <!-- Declare as a performance test module -->
    <option name="config-descriptor:metadata" key="test-type" value="performance" />
    <option name="test-tag" value="hello-world-performance-test" />
    <test class="com.android.tradefed.testtype.HostTest" >
        <option name="class" value="android.test.example.helloworldperformance.HelloWorldPerformanceTest" />
    </test>
    <!-- Add module-level post processor MetricFilePostProcessor -->
    <metric_post_processor class="com.android.tradefed.postprocessor.MetricFilePostProcessor">
        <option name="aggregate-similar-tests" value="true" />
        <option name="enable-per-test-log" value="false" />
    </metric_post_processor>
</configuration>