

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 適用於 Android 和 AWS Device Farm 的檢測
<a name="test-types-android-instrumentation"></a>

Device Farm 支援 Android 的檢測 (JUnit、Espresso、Robotium 或任何檢測型測試）。

Device Farm 也提供範例 Android 應用程式，以及三個 Android 自動化架構中的工作測試連結，包括檢測 (Espresso)。適用於 [Android 的 Device Farm 範例應用程式](https://github.com/awslabs/aws-device-farm-sample-app-for-android)可在 GitHub 下載。

如需在 Device Farm 中測試的詳細資訊，請參閱 [AWS Device Farm 中的測試架構和內建測試](test-types.md)。

**Topics**
+ [什麼是檢測？](#test-types-android-instrumentation-what-is)
+ [Android 檢測測試的考量事項](#test-types-android-instrumentation-settings)
+ [標準模式測試剖析](#test-types-android-standard-mode-test-parse)
+ [將 Android Instrumentation 與 Device Farm 整合](test-types-android-instrumentation-integrate.md)

## 什麼是檢測？
<a name="test-types-android-instrumentation-what-is"></a>

Android 檢測可讓您在測試程式碼中叫用回呼方法，這樣您就可以逐步執行元件的生命週期，類似於偵錯元件。如需詳細資訊，請參閱 *Android 開發人員工具*文件的測試*類型和位置*一節中的[檢測](https://developer.android.com/studio/test/test-in-android-studio#test_types_and_locations)測試。

## Android 檢測測試的考量事項
<a name="test-types-android-instrumentation-settings"></a>

使用 Android 檢測時，請考慮下列建議和備註。

**檢查 Android 作業系統相容性**  
 檢查 [Android 文件 ](https://developer.android.com/jetpack/androidx/releases/test#orchestrator-1.5.0)，以確保檢測與您的 Android 作業系統版本相容。

**從命令列執行**  
 若要從命令列執行檢測測試，請遵循 [Android 文件。](https://developer.android.com/training/testing/instrumented-tests/androidx-test-libraries/runner#enable-command)

**System Animations (動畫系統)**  
 根據 [Espresso 測試的 Android 文件](https://developer.android.com/training/testing/espresso)，建議在實際裝置上測試時關閉系統動畫。Device Farm 會在使用 [android.support.test.runner.AndroidJUnitRunner](http://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner.html) 檢測測試執行器執行時，自動停用**視窗動畫縮放**、**轉換動畫縮放**和**動畫持續時間縮放**設定。

**Test Recorders (測試錄製器)**  
Device Farm 支援具有record-and-playback指令碼工具的架構，例如 Robotium。

## 標準模式測試剖析
<a name="test-types-android-standard-mode-test-parse"></a>

在標準執行模式中，Device Farm 會剖析您的測試套件，並識別其將執行的唯一測試類別和方法。這是透過名為 [Dex Test Parser](https://github.com/linkedin/dex-test-parser) 的工具來完成。

將 Android 檢測 .apk 檔案指定為輸入時，剖析器會傳回符合 JUnit 3 和 JUnit 4 慣例之測試的完整方法名稱。

若要在本機環境中測試此項目：

1. 下載[https://github.com/linkedin/dex-test-parser](https://github.com/linkedin/dex-test-parser)二進位檔。

1. 執行下列命令以取得將在 Device Farm 上執行的測試方法清單：

   ```
   java -jar parser.jar path/to/apk path/for/output
   ```