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> 的情形如下: 請盡量不要這麼做但不保證能正常運作。

metric_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.xml) 會一次執行此操作,而非由每個 Compatibility Test Suite (CTS) 模組個別查詢裝置資訊、類型等,這樣一來,每個模組在要求時就會收到該資訊。

為了讓模組中的物件接收建構資訊,這些物件必須與一般 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 元件 。這不會對測試執行產生任何直接影響。是 主要用於整理

如需最新的 CTS 可用元件清單,請前往: CtsConfigLoadingTest。 如果將不存在的元件新增至 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_collector 和 允許使用 metric_post_processor,因為這是效能測試的基本要素。 模組層級指標收集器和後置處理器可以是模組專屬。不建議同時在頂層和模組層級指定後置處理器。

效能測試模組設定必須包含 test-type 中繼資料,且值為 performance,例如:xml <option name="config-descriptor:metadata" key="test-type" value="performance" /> 如果沒有這項資訊,當測試設定包含 FilePullerLogCollector 或任何 metric_post_processor 以外的 metric_collector,測試就會在提交前失敗。

效能測試模組設定範例:

<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>