AndroidTest.xml 結構

模組設定的整體結構會採用類似的模式 一般的換購 XML 設定,但由於 就是做為套件的一部分

允許的標記清單

AndroidTest.xml 或更廣泛的模組設定只能包含 下列 XML 標記:target_preparermulti_target_preparertestmetrics_collector

雖然這個清單看起來有點限制,但還是可讓您 測試模組設定需求及要執行測試。

注意:請參閱換購 XML 設定 如果需要複習不同的廣告代碼

build_providerresult_reporter 等物件會觸發 如果嘗試從模組內部執行,則為 ConfigurationException 此外還會從 0 自動調整資源配置 您完全不必調整資源調度設定這麼做是為了避免發生 物件實際上是從模組中執行某些工作

模組設定範例

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

那版本資訊或下載作業呢?

允許的廣告代碼定義,可能會產生不正確的曝光, 但不會取得任何建構資訊但這並不屬實

建構資訊來自套件層級設定, 由「所有」套件模組共用。如此即可允許單一頂層設定 才能執行套件中的所有模組。

舉例來說 Compatibility Test Suite (CTS) 模組個別查詢裝置資訊、類型等, 套件層級設定 (cts.xml) 只會執行一次,而每個模組都會接收到 取得相關資訊

為了讓模組中的物件接收建構資訊, 這與一般交易設定相同:實作 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-filter》和《module-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" /> 如果沒有這項資訊,則當測試設定包含 metric_collector FilePullerLogCollector 或任何 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>