

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

# AWS Device Farm 中的測試架構和內建測試
<a name="test-types"></a>

本節說明 Device Farm 對測試架構和內建測試類型的支援。

Device Farm 會讓您將應用程式和測試上傳到由 服務管理的安全 Amazon S3 儲存貯體，以執行自動化測試。上傳後，它會啟動基礎基礎設施，包括服務受管[測試主機](custom-test-environments-hosts.md)，並在多個裝置上平行執行測試。測試結果會儲存在服務受管 S3 儲存貯體中。此架構稱為**服務端執行**，是在靠近裝置的主機上執行測試的快速且有效率方式，而不需要自行管理測試主機基礎設施。此方法非常適合在許多裝置上獨立進行測試，以及根據 CI/CD 管道的內容進行測試。

如需 Device Farm 如何執行測試的詳細資訊，請參閱 [在 AWS Device Farm 中測試環境](test-environments.md)。

**注意**  
對於 Appium 測試人員，您可能偏好從本機環境執行 Appium 測試。透過[遠端存取工作階段](remote-access.md)，您可以執行**用戶端** Appium 測試。如需詳細資訊，請參閱[用戶端 Appium 測試](appium-endpoint.md)。

## 測試架構
<a name="test-types-framework"></a>

Device Farm 支援這些行動自動化測試架構：

### Android 應用程式測試架構
<a name="test-types-framework-android-list"></a>
+ [自動 Appium 測試與 Appium 測試整合](test-types-appium.md)
+ [檢測](test-types-android-instrumentation.md)

### iOS 應用程式測試架構
<a name="test-types-framework-ios-list"></a>
+ [自動 Appium 測試與 Appium 測試整合](test-types-appium.md)
+ [XCTest](test-types-ios-xctest.md)
+ [XCTest UI](test-types-ios-xctest-ui.md)

### Web 應用程式測試架構
<a name="test-types-framework-web-app-list"></a>

Web 應用程式支援使用 Appium。如需將測試帶入 Appium 的詳細資訊，請參閱 [在 Device Farm 中自動執行 Appium 測試將 Appium 測試與 Device Farm 整合](test-types-appium.md)。

### 自訂測試環境中的架構
<a name="test-types-framework-custom-support"></a>

Device Farm 不支援自訂 XCTest 架構的測試環境。如需詳細資訊，請參閱[AWS Device Farm 中的自訂測試環境](custom-test-environments.md)。

### Appium 版本支援
<a name="test-types-framework-appium"></a>

對於在自訂環境中執行的測試，Device Farm 支援 Appium 第 1 版。如需詳細資訊，請參閱[在 AWS Device Farm 中測試環境](test-environments.md)。

## 內建測試類型
<a name="test-types-built-in"></a>

透過內建測試，您可以在多個裝置上測試應用程式，而無需撰寫和維護測試自動化指令碼。Device Farm 提供一種內建測試類型：
+ [內建：模糊 (Android 和 iOS)](test-types-built-in-fuzz.md)

# 在 Device Farm 中自動執行 Appium 測試
<a name="test-types-appium"></a><a name="test-types-ios-appium-java-testng"></a><a name="test-types-ios-appium-java-junit"></a><a name="test-types-ios-appium-python"></a><a name="test-types-ios-appium-ruby"></a><a name="test-types-ios-appium-node"></a><a name="test-types-android-appium-java-testng"></a><a name="test-types-android-appium-java-junit"></a><a name="test-types-android-appium-python"></a><a name="test-types-android-appium-ruby"></a><a name="test-types-android-appium-node"></a><a name="test-types-web-app-appium-java-testng"></a><a name="test-types-web-app-appium-java-junit"></a><a name="test-types-web-app-appium-python"></a><a name="test-types-web-app-appium-ruby"></a><a name="test-types-web-app-appium-node"></a>

**注意**  
此頁面涵蓋在 Device Farm 的受管**伺服器端**執行環境中執行 Appium 測試。若要在遠端存取工作階段期間從本機**用戶端**環境執行 Appium 測試，請參閱[用戶端 Appium 測試](appium-endpoint.md)。

本節說明如何設定、封裝和上傳 Appium 測試，以便在 Device Farm 的受管伺服器端環境中執行。Appium 是一種開放原始碼工具，用於自動化原生和行動 Web 應用程式。如需詳細資訊，請參閱 [Appium 網站上的 Appium 簡介](http://appium.io/docs/en/latest/intro)。

如需範例應用程式和工作測試的連結，請參閱 GitHub 上的適用於 [Android 的 Device Farm Sample App](https://github.com/aws-samples/aws-device-farm-sample-app-for-android) 和[適用於 iOS 的 Device Farm Sample App](https://github.com/aws-samples/aws-device-farm-sample-app-for-ios)。

如需在 Device Farm 中測試及伺服器端運作方式的詳細資訊，請參閱 [AWS Device Farm 中的測試架構和內建測試](test-types.md)。

## 選取 Appium 版本
<a name="w2aac24c15c41"></a>

**注意**  
 支援特定的 Appium 版本、Appium 驅動程式或程式設計 SDKs 將取決於為測試執行選取的裝置和測試主機。

 Device Farm 測試主機已預先安裝 Appium，以便針對更直接的使用案例更快速地設定測試。不過，使用測試規格檔案可讓您視需要安裝不同版本的 Appium。

### 案例 1：預先設定的 Appium 版本
<a name="w2aac24c15c41b7b1"></a>

 Device Farm 根據測試主機預先設定不同的 Appium 伺服器版本。主機隨附工具，可啟用具有裝置平台預設驅動程式的預先設定版本 （適用於 Android 的 UiAutomator2 和適用於 iOS 的 XCUITest)。

```
phases:
  install:
    commands:
      - export APPIUM_VERSION=2
      - devicefarm-cli use appium $APPIUM_VERSION
```

 若要檢視支援的軟體清單，請參閱 上的 主題[自訂測試環境中支援的軟體](custom-test-environments-hosts-software.md)。

### 案例 2：自訂 Appium 版本
<a name="w2aac24c15c41b7b3"></a>

 若要選取自訂版本的 Appium，請使用 `npm`命令來安裝它。下列範例示範如何安裝最新版的 Appium 2。

```
phases:
  install:
    commands:
      - export APPIUM_VERSION=2
      - npm install -g appium@$APPIUM_VERSION
```

### 案例 3：舊版 iOS 主機上的 Appium
<a name="w2aac24c15c41b7b5"></a>

 在 上[舊版 iOS 測試主機](custom-test-environments-hosts-ios.md#legacy-ios-host)，您可以選擇具有 的特定 Appium 版本`avm`。例如，若要使用 `avm`命令將 Appium 伺服器版本設定為 `2.1.2`，請將這些命令新增至您的測試規格 YAML 檔案。

```
phases:
  install:
    commands:
      - export APPIUM_VERSION=2.1.2
      - avm $APPIUM_VERSION
```

## 為 iOS 測試選取 WebDriverAgent 版本
<a name="test-types-appium-select-wda"></a>

 若要在 iOS 裝置上執行 Appium 測試，必須使用 WebDriverAgent。此應用程式必須經過簽署，才能安裝在 iOS 裝置上。Device Farm 提供預先簽章的 WebDriverAgent 版本，可在自訂測試環境執行期間使用。

 下列程式碼片段可用於在與 XCTestUI 驅動程式版本相容的測試規格檔案中，選取 Device Farm 上的 WebDriverAgent 版本。

```
phases:
  pre_test:
    commands:
      - |-
        APPIUM_DRIVER_VERSION=$(appium driver list --installed --json | jq -r ".xcuitest.version" | cut -d "." -f 1);
        CORRESPONDING_APPIUM_WDA=$(env | grep "DEVICEFARM_APPIUM_WDA_DERIVED_DATA_PATH_V${APPIUM_DRIVER_VERSION}")
        if [[ ! -z "$APPIUM_DRIVER_VERSION" ]] && [[ ! -z "$CORRESPONDING_APPIUM_WDA" ]]; then
          echo "Using Device Farm's prebuilt WDA version ${APPIUM_DRIVER_VERSION}.x, which corresponds with your driver";
          DEVICEFARM_APPIUM_WDA_DERIVED_DATA_PATH=$(echo $CORRESPONDING_APPIUM_WDA | cut -d "=" -f2)
        else
          LATEST_SUPPORTED_WDA_VERSION=$(env | grep "DEVICEFARM_APPIUM_WDA_DERIVED_DATA_PATH_V" | sort -V -r | head -n 1)
          echo "Unknown driver version $APPIUM_DRIVER_VERSION; falling back to the Device Farm default version of $LATEST_SUPPORTED_WDA_VERSION";
          DEVICEFARM_APPIUM_WDA_DERIVED_DATA_PATH=$(echo $LATEST_SUPPORTED_WDA_VERSION | cut -d "=" -f2)
        fi;
```

 如需 WebDriverAgent 的詳細資訊，請參閱 Appium [的文件](https://appium.github.io/appium-xcuitest-driver/9.10/guides/run-prebuilt-wda/)。

# 將 Appium 測試與 Device Farm 整合
<a name="test-types-appium-integrate"></a>

使用下列指示將 Appium 測試與 AWS Device Farm 整合。如需在 Device Farm 中使用 Appium 測試的詳細資訊，請參閱 [在 Device Farm 中自動執行 Appium 測試將 Appium 測試與 Device Farm 整合](test-types-appium.md)。

## 設定您的 Appium 測試套件
<a name="test-types-appium-prepare"></a>

使用以下指示來設定您的測試套件。

------
#### [ Java (JUnit) ]

1. 修改 `pom.xml` 以將封裝設定為 JAR 檔案：

   ```
   <groupId>com.acme</groupId>
   <artifactId>acme-myApp-appium</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>
   ```

1. 修改 `pom.xml` 以使用 `maven-jar-plugin` 將測試建置到 JAR 檔案。

   下列外掛程式會將您的測試原始程式碼 (`src/test`目錄中的任何項目） 建置為 JAR 檔案：

   ```
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-jar-plugin</artifactId>
     <version>2.6</version>
     <executions>
       <execution>
         <goals>
           <goal>test-jar</goal>
         </goals>
       </execution>
     </executions>
   </plugin>
   ```

1. 修改 `maven-dependency-plugin` 以`pom.xml`使用 建置相依性做為 JAR 檔案。

   下列外掛程式會將您的相依性複製到 `dependency-jars`目錄：

   ```
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <version>2.10</version>
     <executions>
       <execution>
         <id>copy-dependencies</id>
         <phase>package</phase>
         <goals>
           <goal>copy-dependencies</goal>
         </goals>
         <configuration>
           <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
         </configuration>
       </execution>
     </executions>
   </plugin>
   ```

1. 將下列 XML 組件儲存至 `src/main/assembly/zip.xml`。

   下列 XML 是組件定義，設定後會指示 Maven 建置 .zip 檔案，其中包含建置輸出目錄根目錄和`dependency-jars`目錄中的所有內容：

   ```
   <assembly
       xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
     <id>zip</id>
     <formats>
       <format>zip</format>
     </formats>
     <includeBaseDirectory>false</includeBaseDirectory>
     <fileSets>
       <fileSet>
         <directory>${project.build.directory}</directory>
         <outputDirectory>./</outputDirectory>
         <includes>
           <include>*.jar</include>
         </includes>
       </fileSet>
       <fileSet>
         <directory>${project.build.directory}</directory>
         <outputDirectory>./</outputDirectory>
         <includes>
           <include>/dependency-jars/</include>
         </includes>
       </fileSet>
     </fileSets>
   </assembly>
   ```

1. 修改 `pom.xml` 以使用 `maven-assembly-plugin` 將測試和所有相依性封裝至單一 .zip 檔案。

   下列外掛程式使用上述組件，在每次執行建置輸出目錄中建立名為 `zip-with-dependencies`的 **mvn package** .zip 檔案：

   ```
   <plugin>
     <artifactId>maven-assembly-plugin</artifactId>
     <version>2.5.4</version>
     <executions>
       <execution>
         <phase>package</phase>
         <goals>
           <goal>single</goal>
         </goals>
         <configuration>
           <finalName>zip-with-dependencies</finalName>
           <appendAssemblyId>false</appendAssemblyId>
           <descriptors>
             <descriptor>src/main/assembly/zip.xml</descriptor>
           </descriptors>
         </configuration>
       </execution>
     </executions>
   </plugin>
   ```

**注意**  
如果您收到錯誤，指明 1.3 中不支援註釋，請將以下內容新增至 `pom.xml`：  

```
<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.7</source>
    <target>1.7</target>
  </configuration>
</plugin>
```

------
#### [ Java (TestNG) ]

1. 修改 `pom.xml` 以將封裝設定為 JAR 檔案：

   ```
   <groupId>com.acme</groupId>
   <artifactId>acme-myApp-appium</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>
   ```

1. 修改 `pom.xml` 以使用 `maven-jar-plugin` 將測試建置到 JAR 檔案。

   下列外掛程式會將您的測試原始程式碼 (`src/test`目錄中的任何項目） 建置為 JAR 檔案：

   ```
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-jar-plugin</artifactId>
     <version>2.6</version>
     <executions>
       <execution>
         <goals>
           <goal>test-jar</goal>
         </goals>
       </execution>
     </executions>
   </plugin>
   ```

1. 修改 `maven-dependency-plugin` 以`pom.xml`使用 建置相依性做為 JAR 檔案。

   下列外掛程式會將您的相依性複製到 `dependency-jars`目錄：

   ```
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <version>2.10</version>
     <executions>
       <execution>
         <id>copy-dependencies</id>
         <phase>package</phase>
         <goals>
           <goal>copy-dependencies</goal>
         </goals>
         <configuration>
           <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
         </configuration>
       </execution>
     </executions>
   </plugin>
   ```

1. 將下列 XML 組件儲存至 `src/main/assembly/zip.xml`。

   下列 XML 是組件定義，設定後會指示 Maven 建置 .zip 檔案，其中包含建置輸出目錄根目錄和`dependency-jars`目錄中的所有內容：

   ```
   <assembly
       xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
     <id>zip</id>
     <formats>
       <format>zip</format>
     </formats>
     <includeBaseDirectory>false</includeBaseDirectory>
     <fileSets>
       <fileSet>
         <directory>${project.build.directory}</directory>
         <outputDirectory>./</outputDirectory>
         <includes>
           <include>*.jar</include>
         </includes>
       </fileSet>
       <fileSet>
         <directory>${project.build.directory}</directory>
         <outputDirectory>./</outputDirectory>
         <includes>
           <include>/dependency-jars/</include>
         </includes>
       </fileSet>
     </fileSets>
   </assembly>
   ```

1. 修改 `pom.xml` 以使用 `maven-assembly-plugin` 將測試和所有相依性封裝至單一 .zip 檔案。

   下列外掛程式使用上述組件，在每次執行建置輸出目錄中建立名為 `zip-with-dependencies`的 **mvn package** .zip 檔案：

   ```
   <plugin>
     <artifactId>maven-assembly-plugin</artifactId>
     <version>2.5.4</version>
     <executions>
       <execution>
         <phase>package</phase>
         <goals>
           <goal>single</goal>
         </goals>
         <configuration>
           <finalName>zip-with-dependencies</finalName>
           <appendAssemblyId>false</appendAssemblyId>
           <descriptors>
             <descriptor>src/main/assembly/zip.xml</descriptor>
           </descriptors>
         </configuration>
       </execution>
     </executions>
   </plugin>
   ```

**注意**  
如果您收到錯誤，指明 1.3 中不支援註釋，請將以下內容新增至 `pom.xml`：  

```
<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.7</source>
    <target>1.7</target>
  </configuration>
</plugin>
```

------
#### [ Node.JS ]

若要封裝 Appium Node.js 測試並將其上傳至 Device Farm，您必須在本機電腦上安裝下列項目：
+ [Node Version Manager (nvm)](https://github.com/nvm-sh/nvm) 

  請使用此工具開發和封裝測試，以便在測試套件中排除不必要的相依性。
+ Node.js
+ npm-bundle (全域安裝)

1. 確認 nvm 已存在

   ```
   command -v nvm
   ```

   您應該會在輸出中看到 `nvm`。

   如需詳細資訊，請參閱 GitHub 上的 [nvm](https://github.com/nvm-sh/nvm)。

1. 執行此命令以安裝 Node.js：

   ```
   nvm install node
   ```

   您可以指定特定版本的 Node.js：

   ```
   nvm install 11.4.0
   ```

1. 確認使用的是正確版本的節點：

   ```
   node -v
   ```

1. 全域安裝 **npm-bundle**：

   ```
   npm install -g npm-bundle
   ```

------
#### [ Python ]

1. 強烈建議您設定 [Python virtualenv](https://pypi.python.org/pypi/virtualenv) 來進行開發和封裝測試，這樣您的應用程式套件就不會包含不必要的相依性。

   ```
   $ virtualenv workspace
   $ cd workspace
   $ source bin/activate
   ```
**提示**  
請不要使用 `--system-site-packages` 選項建立 Python virtualenv，因為它會從全域 site-packages 目錄繼承套件。這可能會導致您的虛擬環境包含測試不需要的相依性。
您還必須驗證您的測試未使用相依於原生程式庫的相依性，因為這些原生程式庫可能不會出現在執行測試的執行個體上。

1. 將 **py.test** 安裝到虛擬環境中。

   ```
   $ pip install pytest
   ```

1. 在您的虛擬環境中安裝 Appium Python 用戶端。

   ```
   $ pip install Appium-Python-Client
   ```

1. 除非您在自訂模式中指定不同的路徑，否則 Device Farm 預期您的測試會存放在 中`tests/`。您可以使用 `find` 來顯示資料夾內的所有檔案：

   ```
   $ find tests/
   ```

   確認這些檔案包含您要在 Device Farm 上執行的測試套件

   ```
   tests/
   tests/my-first-tests.py
   tests/my-second-tests/py
   ```

1. 從虛擬環境工作區資料夾中執行此命令，以顯示測試的清單而不予以執行。

   ```
   $ py.test --collect-only tests/
   ```

   確認輸出顯示您想要在 Device Farm 上執行的測試。

1. 清理您的測試資料夾下的所有快取檔案：

   ```
   $ find . -name '__pycache__' -type d -exec rm -r {} +
   $ find . -name '*.pyc' -exec rm -f {} +
   $ find . -name '*.pyo' -exec rm -f {} +
   $ find . -name '*~' -exec rm -f {} +
   ```

1. 在工作區中執行下列命令，以產生 requirements.txt 檔案：

   ```
   $ pip freeze > requirements.txt
   ```

------
#### [ Ruby ]

若要封裝 Appium Ruby 測試並將其上傳至 Device Farm，您必須在本機電腦上安裝下列項目：
+ [Ruby Version Manager (RVM)](https://rvm.io/rvm/install)

  請使用此命令列工具開發和封裝測試，以便在測試套件中排除不必要的相依性。
+ Ruby
+ Bundler (此 gem 套件通常會隨 Ruby 安裝)。

1. 安裝所需的金鑰、RVM 和 Ruby。如需詳細資訊，請參閱 RVM 網站上的[安裝 RVM](https://rvm.io/rvm/install)。

   在安裝完成時，藉由登出再重新登入，來重新載入終端機。
**注意**  
RVM 只會做為 bash shell 的函數載入。

1. 確認已正確安裝 **rvm**

   ```
   command -v rvm
   ```

   您應該會在輸出中看到 `rvm`。

1. 如果您想要安裝特定版本的 Ruby，例如 *2.5.3*，請執行下列命令：

   ```
   rvm install ruby 2.5.3 --autolibs=0
   ```

   確認使用的是要求的 Ruby 版本：

   ```
   ruby -v
   ```

1. 設定 Bundler 來編譯所需測試平台的套件：

   ```
   bundle config specific_platform true
   ```

1. 更新您的 .lock 檔案以新增執行測試所需的平台。
   + 如果您要編譯測試以在 Android 裝置上執行，請執行此命令來設定 Gemfile 以使用 Android 測試主機的相依性：

     ```
     bundle lock --add-platform x86_64-linux
     ```
   + 如果您要編譯測試以在 iOS 裝置上執行，請執行此命令來設定 Gemfile 以使用 iOS 測試主機的相依性：

     ```
     bundle lock --add-platform x86_64-darwin
     ```

1. 通常預設為安裝 **bundler** gem。如果不是，請安裝它：

   ```
   gem install bundler -v 2.3.26
   ```

------

## 建立壓縮的測試套件檔案
<a name="test-types-appium-create-a-zip"></a>

**警告**  
在 Device Farm 中，壓縮測試套件中檔案的資料夾結構很重要，有些封存工具會隱含地變更 ZIP 檔案的結構。我們建議您遵循以下指定的命令列公用程式，而不是使用本機桌面 （例如 Finder 或 Windows Explorer) 的檔案管理員內建的封存公用程式。

現在，針對 Device Farm 將您的測試綁定在一起。

------
#### [ Java (JUnit) ]

建置並封裝您的測試：

```
$ mvn clean package -DskipTests=true
```

結果會建立檔案 `zip-with-dependencies.zip`。這是您的測試套件。

------
#### [ Java (TestNG) ]

建置並封裝您的測試：

```
$ mvn clean package -DskipTests=true
```

結果會建立檔案 `zip-with-dependencies.zip`。這是您的測試套件。

------
#### [ Node.JS ]

1. 檢查您的專案。

   確定您位於專案的根目錄。您可以在根目錄看到 `package.json`。

1. 執行此命令來安裝本機相依性。

   ```
   npm install
   ```

   此命令也會在目前的目錄中建立 `node_modules` 資料夾。
**注意**  
此時，您應該能夠在本機執行測試。

1. 執行此命令將目前資料夾中的檔案封裝成 \$1.tgz 檔案。檔案會使用 `package.json` 檔案中的 `name` 屬性來命名。

   ```
   npm-bundle
   ```

   這個 tarball (.tgz) 檔案包含所有程式碼和相依性。

1. 執行此命令將前一步驟所產生的 tarball (\$1.tgz 檔案) 套裝成單一壓縮的存檔：

   ```
   zip -r MyTests.zip *.tgz
   ```

   這是您在下列程序中上傳至 Device Farm `MyTests.zip` 的檔案。

------
#### [ Python ]

Python 2  
使用 pip 產生所需 Python 套件的存檔 (稱為「wheelhouse」)：  

```
$ pip wheel --wheel-dir wheelhouse -r requirements.txt
```
針對 Device Farm 將您的 wheelhouse、測試和 pip 要求封裝到 zip 存檔中：  

```
$ zip -r test_bundle.zip tests/ wheelhouse/ requirements.txt
```

Python 3  
將您的測試和 pip 要求封裝到一個 zip 檔案中：  

```
$ zip -r test_bundle.zip tests/ requirements.txt
```

------
#### [ Ruby ]

1. 執行此命令來建立虛擬 Ruby 環境：

   ```
   # myGemset is the name of your virtual Ruby environment
   rvm gemset create myGemset
   ```

1. 執行此命令來使用您剛建立的環境：

   ```
   rvm gemset use myGemset
   ```

1. 檢查您的原始程式碼。

   確定您位於專案的根目錄。您可以在根目錄看到 `Gemfile`。

1. 執行此命令從 `Gemfile` 安裝本機相依性和所有 gem 套件：

   ```
   bundle install
   ```
**注意**  
此時，您應該能夠在本機執行測試。使用此命令從本機執行測試：  

   ```
   bundle exec $test_command
   ```

1. 將您的 gem 套件封裝在 `vendor/cache` 資料夾中。

   ```
   # This will copy all the .gem files needed to run your tests into the vendor/cache directory
   bundle package --all-platforms
   ```

1. 執行以下命令將您的原始程式碼及所有相依性套裝到單一壓縮的存檔：

   ```
   zip -r MyTests.zip Gemfile vendor/ $(any other source code directory files)
   ```

   這是您在下列程序中上傳至 Device Farm `MyTests.zip` 的檔案。

------

## 將您的測試套件上傳至 Device Farm
<a name="test-types-appium-upload"></a>

您可以使用 Device Farm 主控台上傳您的測試。

1. 登入 Device Farm 主控台，網址為 https：//[https://console.aws.amazon.com/devicefarm](https://console.aws.amazon.com/devicefarm)。

1. 在 Device Farm 導覽面板上，選擇**行動裝置測試**，然後選擇**專案**。

1. 如果您是新使用者，請選擇**新增專案**，輸入專案的名稱，然後選擇**提交**。

   如果您已經有專案，您可以選擇它來上傳您的測試到該專案。

1. 開啟您的專案，然後選擇**建立執行**。

1. 在**執行設定**下，為您的測試指定適當的名稱。這可包含空格或標點符號的任何組合。

1.   
若是原生 Android 和 iOS 測試  
在**執行設定**下，如果您要測試 **Android** (.apk) 應用程式，請選擇 Android 應用程式；如果您要測試 **iOS** (.ipa) 應用程式，請選擇 iOS 應用程式。然後，在**選取應用程式**下，選取**上傳自己的應用程式**以上傳應用程式的可分發套件。  
 檔案必須是 Android `.apk` 或 iOS `.ipa`。iOS 應用程式必須是專為真實裝置建置，而不是專為模擬器建置。  
若是行動 Web 應用程式測試  
在**執行設定**下，選擇 **Web 應用程式**。

1. 在**設定測試**下，在**選取測試架構**區段中，選擇您使用的測試 Appium 架構，然後**上傳您自己的測試套件**。

1. 瀏覽並選擇包含測試的 .zip 檔案。.zip 檔案必須遵循[設定您的 Appium 測試套件](#test-types-appium-prepare)中所述的格式。

1. 依照指示選取裝置並開始執行。如需詳細資訊，請參閱[在 Device Farm 中建立測試執行](how-to-create-test-run.md)。

**注意**  
Device Farm 不會修改 Appium 測試。

## 擷取測試的螢幕擷取畫面 （選用）
<a name="test-types-appium-screenshots"></a>

您可以在測試時取得螢幕擷取畫面。

Device Farm 會將 `DEVICEFARM_SCREENSHOT_PATH` 屬性設為本機檔案系統上的完整路徑，這是 Device Farm 預期的 Appium 螢幕擷取畫面儲存位置。用於存放螢幕擷取畫面的測試專用目錄是在執行時間定義。系統會自動將螢幕擷取畫面提取到您的 Device Farm 報告。若要檢視螢幕擷取畫面，在 Device Farm 主控台中選擇 **Screenshots (螢幕擷取畫面)** 區段。

 如需在 Appium 測試中擷取螢幕擷取畫面的詳細資訊，請參閱 Appium API 文件中的 [擷取螢幕擷取畫面](http://appium.io/docs/en/commands/session/screenshot/)。

# AWS Device Farm 中的 Android 測試
<a name="test-types-android-tests"></a>

Device Farm 支援多種 Android 裝置的自動化測試類型，以及兩個內建測試。

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

## Android 應用程式測試架構
<a name="test-types-framework-android"></a>

下列測試適用於 Android 裝置。
+ [自動 Appium 測試與 Appium 測試整合](test-types-appium.md)
+ [檢測](test-types-android-instrumentation.md)

## 適用於 Android 的內建測試類型
<a name="test-types-built-in-android"></a>

Android 裝置可使用一種內建測試類型：
+ [內建：模糊 (Android 和 iOS)](test-types-built-in-fuzz.md)

# 適用於 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
   ```

# 將 Android Instrumentation 與 Device Farm 整合
<a name="test-types-android-instrumentation-integrate"></a>

**注意**  
使用下列指示將 Android 檢測測試與 AWS Device Farm 整合。如需在 Device Farm 中使用檢測測試的詳細資訊，請參閱 [適用於 Android 和 AWS Device Farm 的檢測](test-types-android-instrumentation.md)。

## 上傳您的 Android 檢測測試
<a name="test-types-android-instrumentation-upload"></a>

使用 Device Farm 主控台上傳您的測試。

1. 登入 Device Farm 主控台，網址為 https：//[https://console.aws.amazon.com/devicefarm](https://console.aws.amazon.com/devicefarm)。

1. 在 Device Farm 導覽面板上，選擇**行動裝置測試**，然後選擇**專案**。

1. 在專案清單中，選擇要上傳測試的專案。
**提示**  
您可以使用搜尋列，依名稱篩選專案清單。  
若要建立專案，請按照 [在 AWS Device Farm 中建立專案](how-to-create-project.md) 中的說明進行操作。

1. 選取**建立執行**。

1. 在**選取應用程式**下，於**應用程式選取選項**區段中，選取**上傳自己的應用程式**。

1. 瀏覽並選擇您的 Android 應用程式檔案。此檔案必須是 .pak 檔案。

1. 在**設定測試**下，在**選取測試架構**區段中，選擇**檢測**，然後選擇**選擇檔案**。

1. 瀏覽並選擇包含測試的 .apk 檔案。

1. 完成剩餘的說明以選取裝置並開始執行。

## （選用） 在 Android 檢測測試中擷取螢幕擷取畫面
<a name="test-types-android-instrumentation-screenshots"></a>

您可以在 Android 檢測測試中擷取螢幕擷取畫面。

若要擷取螢幕擷取畫面，請呼叫下列其中一個方法：
+ 若您使用 Robotium，請呼叫 `takeScreenShot` 方法 (例如，`solo.takeScreenShot();`)。
+ 若您使用 Spoon，請呼叫 `screenshot` 方法，例如：

  ```
  Spoon.screenshot(activity, "initial_state");
  /* Normal test code... */
  Spoon.screenshot(activity, "after_login");
  ```

在測試執行期間， Device Farm 會從裝置上存在的下列位置取得螢幕擷取畫面，然後將它們新增至測試報告：
+ `/sdcard/robotium-screenshots`
+ `/sdcard/test-screenshots`
+ `/sdcard/Download/spoon-screenshots/test-class-name/test-method-name`
+ `/data/data/application-package-name/app_spoon-screenshots/test-class-name/test-method-name`

# AWS Device Farm 中的 iOS 測試
<a name="test-types-ios-tests"></a>

Device Farm 支援 iOS 裝置的多種自動化測試類型，以及內建測試。

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

## iOS 應用程式測試架構
<a name="test-types-framework-ios"></a>

下列測試適用於 iOS 裝置。
+ [自動 Appium 測試與 Appium 測試整合](test-types-appium.md)
+ [XCTest](test-types-ios-xctest.md)
+ [XCTest UI](test-types-ios-xctest-ui.md)

## 適用於 iOS 的內建測試類型
<a name="test-types-built-in-ios"></a>

目前有一種內建測試類型適用於 iOS 裝置。
+ [內建：模糊 (Android 和 iOS)](test-types-built-in-fuzz.md)

# 將 Device Farm 與適用於 iOS 的 XCTest 整合
<a name="test-types-ios-xctest"></a>

使用 Device Farm，您可以使用 XCTest 架構在實際裝置上測試您的應用程式。如需 XCTest 的詳細資訊，請參閱*使用 Xcode 在測試*中[測試基本概念](https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/03-testing_basics.html)。

若要執行測試，請為測試執行建立套件，並將這些套件上傳至 Device Farm。

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

**Topics**
+ [為您的 XCTest 執行建立套件](#test-types-ios-xctest-create-packages)
+ [將 XCTest 執行的套件上傳至 Device Farm](#test-types-ios-xctest-upload)

## 為您的 XCTest 執行建立套件
<a name="test-types-ios-xctest-create-packages"></a>

若要使用 XCTest 架構測試您的應用程式，Device Farm 需要下列項目：
+ 以 `.ipa` 檔案提供的應用程式套件。
+ 以 `.zip` 檔案提供的 XCTest 套件。

您使用 Xcode 產生的組建輸出來建立這些套件。請完成下列步驟來建立套件，以便您可以將它們上傳到 Device Farm。

**為應用程式產生組建輸出**

1. 在 Xcode 中打开应用程序项目。

1. 在 Xcode 工具列的配置下拉式功能表中，選擇 **Generic iOS Device (一般 iOS 裝置)** 做為目的地。

1. 在 **Product (產品)** 功能表中，選擇 **Build For (建置對象)**，然後選擇 **Testing (測試)**。

**建立應用程式套件**

1. 在 Xcode 的專案導覽器中，在 **Products (產品)** 下方開啟名為 `app-project-name.app` 之檔案的內容功能表。然後，選擇 **Show in Finder (在尋找工具中顯示)**。Finder 會開啟名為 `Debug-iphoneos` 的資料夾，其中包含 Xcode 為您的測試組建產生的輸出。此資料夾包含您的 `.app` 檔案。

1. 在 Finder 中，建立一個新資料夾並將其命名為 `Payload`.

1. 複製 `app-project-name.app` 檔案，並將其貼至 `Payload` 資料夾。​

1. 開啟 `Payload` 資料夾的內容功能表，然後選擇 **Compress "Payload" (壓縮 "Payload")**。名為 `Payload.zip` 的檔案已建立。

1. 將 `Payload.zip` 的檔案名稱和副檔名變更為 `app-project-name.ipa`。

   在後續步驟中，您會將此檔案提供給 Device Farm。為了能更容易找到此檔案，您可以將它移到另一個位置，例如桌面。

1. 或者，您也可以刪除 `Payload` 資料夾和其中的 `.app` 檔案。

**建立 XCTest 套件**

1. 在 Finder 的 `Debug-iphoneos` 目錄中，開啟 `app-project-name.app` 檔案的內容功能表。然後，選擇 **Show Package Contents (顯示套件內容)**。

1. 在套件內容中，開啟 `Plugins` 資料夾。此資料夾包含名為 `app-project-name.xctest` 的檔案。

1. 開啟此檔案的內容選單，然後選擇**壓縮「`app-project-name.xctest`」**。名為 `app-project-name.xctest.zip` 的檔案已建立。

   在後續步驟中，您會將此檔案提供給 Device Farm。為了能更容易找到此檔案，您可以將它移到另一個位置，例如桌面。

## 將 XCTest 執行的套件上傳至 Device Farm
<a name="test-types-ios-xctest-upload"></a>

使用 Device Farm 主控台上傳測試的套件。

1. 登入 Device Farm 主控台，網址為 https：//[https://console.aws.amazon.com/devicefarm](https://console.aws.amazon.com/devicefarm)。

1. 如果您還沒有專案，請加以建立。如需建立專案的步驟，請參閱[在 AWS Device Farm 中建立專案](how-to-create-project.md)。

   否則，在 Device Farm 導覽面板上，選擇**行動裝置測試**，然後選擇**專案**。

1. 選擇您要用來執行測試的專案。

1. 選擇**建立執行**。

1. 在**執行設定**下，於**執行類型**區段中，選擇 **iOS 應用程式**。

1. 在**選取應用程式**下，於**應用程式選取選項**區段中，選取**上傳自己的應用程式**。然後，選取**上傳應用程式**下的**選擇檔案**。

1. 瀏覽至您應用程式的 `.ipa` 檔案並上傳。
**注意**  
您的 `.ipa` 套件必須是專為測試而建置。

1. 在**設定測試**下，於**選取測試架構**區段中，選擇 **XCTest**。然後，選取**上傳應用程式**下的**選擇檔案**。

1. 瀏覽到其中包含用於您應用程式之 XCTest 套件的 `.zip` 檔案，並將其上傳。

1. 完成專案建立程序的其餘步驟。您將會選擇您想要進行測試的裝置，並指定裝置狀態。

1. 選擇**建立執行**。Device Farm 會執行您的測試，並在主控台中顯示結果。

# 將適用於 iOS 的 XCTest UI 與 Device Farm 整合
<a name="test-types-ios-xctest-ui"></a>

Device Farm 支援 XCTest UI 測試架構。具體而言，Device Farm 支援以 Objective-C 和 [Swift](https://developer.apple.com/swift/) 編寫的 XCTest UI 測試。

 XCTest UI 架構可在 iOS 開發中啟用 UI 測試，建置於 XCTest 之上。如需詳細資訊，請參閱 iOS Developer Library 中的 [使用者界面測試](https://developer.apple.com/library/prerelease/ios/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/09-ui_testing.html#//apple_ref/doc/uid/TP40014132-CH13-SW1)。

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

使用以下指示，將 Device Farm 與適用於 iOS 的 XCTest UI 測試架構整合。

**Topics**
+ [準備您的 iOS XCTest UI 測試](#test-types-ios-xctest-ui-prepare)
+ [選項 1：建立 XCTest UI .ipa 套件](#how-to-use-create-XCTestUI-ipa-package)
+ [選項 2：建立 XCTest UI .zip 套件](#how-to-use-create-XCTestUI-zip-package)
+ [上傳您的 iOS XCTest UI 測試](#test-types-ios-xctest-ui-upload)

## 準備您的 iOS XCTest UI 測試
<a name="test-types-ios-xctest-ui-prepare"></a>

您可以上傳`.ipa`檔案或 XCTEST\$1UI 測試套件`.zip`的檔案。

`.ipa` 檔案是應用程式封存，其中包含套件格式的 iOS Runner 應用程式。*檔案內不可包含其他`.ipa`檔案。*

如果您上傳`.zip`檔案，它可以直接包含 iOS Runner 應用程式或 `.ipa` 檔案。如果您想要在測試期間使用檔案，也可以在`.zip`檔案中包含其他檔案。例如，您可以包含 或 等`.zip`檔案`.xctestrun``.xcworkspace``.xcodeproj`，在裝置陣列上執行 XCUI 測試計劃。有關如何執行 Test Plans 的詳細指示可在 XCUI 測試類型的預設測試規格檔案中取得。

## 選項 1：建立 XCTest UI .ipa 套件
<a name="how-to-use-create-XCTestUI-ipa-package"></a>

當您建置專案進行測試時，Xcode 會產生 *yourAppName*UITest-Runner.app 套件。您可以在專案的「產品」目錄中找到該 bundle。

若要建立 .ipa 檔案：

1. 建立名為*承載*的目錄。

1. 將您的應用程式目錄新增至承載目錄。

1. 將承載目錄封存至`.zip`檔案，然後將副檔名變更為 `.ipa`。

 下列資料夾結構顯示名為 *my-project-nameUITest-Runner.app* 的範例應用程式如何封裝為 `.ipa` 檔案：

```
.
└── my-project-nameUITest.ipa
    └── Payload (directory)
        └── my-project-nameUITest-Runner.app
```

## 選項 2：建立 XCTest UI .zip 套件
<a name="how-to-use-create-XCTestUI-zip-package"></a>

Device Farm 會自動為您產生執行完整 XCTest UI 測試套件`.xctestrun`的檔案。如果您想要在 Device Farm 上使用自己的`.xctestrun`檔案，您可以將`.xctestrun`檔案和應用程式目錄壓縮為 `.zip` 檔案。如果您已有測試套件的檔案，您可以在這裡包含該`.ipa`檔案，而不是 *\$1-Runner.app*。

```
.
└── swift-sample-UI.zip (directory)
   ├── my-project-nameUITest-Runner.app [OR] my-project-nameUITest.ipa
   ├── SampleTestPlan_2.xctestrun
   ├── SampleTestPlan_1.xctestrun
   └── (any other files)
```

 如果您想要在 Device Farm 上執行 XCUI 測試的 Xcode 測試計畫，您可以建立包含 *my-project-nameUITest-Runner.app* **或** *my-project-nameUITest.ipa* 檔案的 zip，以及使用測試計畫執行 XCTEST\$1UI 所需的 xcode 原始程式碼檔案，包括 `.xcworkspace`或 `.xcodeproj` 檔案。

以下是使用 `.xcodeproj` 檔案的範例 zip：

```
.
└── swift-sample-UI.zip (directory)
   ├── my-project-nameUITest-Runner.app [OR] my-project-nameUITest.ipa
   ├── (any directory)
   └── SampleXcodeProject.xcodeproj
        ├── Testplan_1.xctestplan
        ├── Testplan_2.xctestplan
        └── (any other source code files created by xcode with .xcodeproj)
```

以下是使用 `.xcworkspace` 檔案的範例 zip：

```
.
└──swift-sample-UI.zip (directory)
   ├── my-project-nameUITest-Runner.app [OR] my-project-nameUITest.ipa
   └── (any directory)
   │   ├── SampleXcodeProject.xcodeproj
   │   ├── Testplan_1.xctestplan
   │   ├── Testplan_2.xctestplan
   |   └── (any other source code files created by xcode with .xcodeproj)
   └── SampleWorkspace.xcworkspace
       └── contents.xcworkspacedata
```

**注意**  
請確定 XCTest UI .zip 套件內沒有名為 "Payload" 的目錄。

## 上傳您的 iOS XCTest UI 測試
<a name="test-types-ios-xctest-ui-upload"></a>

使用 Device Farm 主控台上傳您的測試。

1. 登入 Device Farm 主控台，網址為 https：//[https://console.aws.amazon.com/devicefarm](https://console.aws.amazon.com/devicefarm)。

1. 在 Device Farm 導覽面板上，選擇**行動裝置測試**，然後選擇**專案**。

1. 在專案清單中，選擇要上傳測試的專案。
**提示**  
您可以使用搜尋列，依名稱篩選專案清單。  
若要建立專案，請遵循 中的指示 [在 AWS Device Farm 中建立專案](how-to-create-project.md)

1. 選擇**建立執行**。

1. 在**執行設定**下，於**執行類型**區段中，選擇 **iOS 應用程式**。

1. 在**選取應用程式**下，於**應用程式選取選項**區段中，選取**上傳自己的應用程式**。然後，選取**上傳應用程式**下的**選擇檔案**。

1. 瀏覽並選擇您的 iOS 應用程式檔案。該檔案必須是 .ipa 檔案。
**注意**  
請確定您的 .ipa 檔案是針對 iOS 裝置所建置，而非模擬器。

1. 在**設定測試**下，於**選取測試架構**區段中，選擇 **XCTest UI**。然後，選取**上傳應用程式**下的**選擇檔案**。

1. 瀏覽並選擇包含 iOS XCTest UI 測試執行器的 .ipa 或 .zip 檔案。

1. 完成執行建立程序中剩餘的步驟。您將選取要測試的裝置，並選擇性地指定其他組態。

1. 選擇**建立執行**。Device Farm 會執行您的測試，並在主控台中顯示結果。

# AWS Device Farm 中的 Web 應用程式測試
<a name="test-types-web-app-tests"></a>

Device Farm 提供適用於 Web 應用程式的 Appium 測試。如需在 Device Farm 上設定 Appium 測試的詳細資訊，請參閱 [在 Device Farm 中自動執行 Appium 測試](test-types-appium.md)。

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

## 計量和未計量裝置的規則
<a name="web-app-tests-metered-unmetered-devices-rules"></a>

計量是指裝置的計費。根據預設，會測量 Device Farm 裝置，並在免費試用分鐘用盡之後，每分鐘向您收取費用。您也可以選擇購買無限制裝置，每月付固定費用即可享有無限制測試。如需定價的詳細資訊，請參閱 [AWS Device Farm 定價](https://aws.amazon.com/device-farm/)。

如果您選擇使用包含 iOS 和 Android 裝置的裝置集區來啟動執行，則另有針對計量和無限制裝置的規則。例如，如果您有五個無限制的 Android 裝置和五個無限制的 iOS 裝置，則 Web 測試執行會使用無限制裝置。

 以下是另一個範例：假設您有五個無限制的 Android 裝置和零個無限制的 iOS 裝置。如果您僅選擇 Android 裝置用於 Web 執行，則系統會使用您的無限制裝置。如果您同時選擇 Android 和 iOS 裝置用於 Web 執行，則系統會依計量收費，且不使用您的無限制裝置。

# AWS Device Farm 中的內建測試
<a name="test-types-built-in-tests"></a>

Device Farm 支援 Android 和 iOS 裝置的內建測試類型。

透過內建測試，您可以在多個裝置上測試應用程式，而無需撰寫和維護測試自動化指令碼。這可以節省您的時間和精力，尤其是當您開始使用 Device Farm 時。Device Farm 提供下列內建測試類型：
+ [內建：模糊 (Android 和 iOS)](test-types-built-in-fuzz.md) – 模糊測試會隨機將使用者介面事件傳送到裝置，然後報告結果。

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



# 執行 Device Farm 的內建模糊測試 (Android 和 iOS)
<a name="test-types-built-in-fuzz"></a>

Device Farm 的內建模糊測試會隨機將使用者介面事件傳送到裝置，然後報告結果。

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

**執行內建模糊測試**

1. 登入 Device Farm 主控台，網址為 https：//[https://console.aws.amazon.com/devicefarm](https://console.aws.amazon.com/devicefarm)。

1. 在 Device Farm 導覽面板上，選擇**行動裝置測試**，然後選擇**專案**。

1. 在專案清單中，選擇您要執行內建模糊測試的專案。
**提示**  
您可以使用搜尋列，依名稱篩選專案清單。  
若要建立專案，請按照 [在 AWS Device Farm 中建立專案](how-to-create-project.md) 中的說明進行操作。

1. 選擇**建立執行**。

1. 在**執行設定**下，選取執行類型區段中的**執行類型**。如果您沒有準備好進行測試的應用程式，或正在測試 Android **應用程式** (.apk)，請選取 Android 應用程式。如果您要測試 **iOS** (.ipa) 應用程式，請選取 iOS 應用程式。

1. 在**選取應用程式**下，如果您沒有可供測試的應用程式，請選擇**選取 Device Farm 提供的範例**應用程式。如果您要使用自己的應用程式，請選取**上傳自己的應用程式 **，然後選擇您的應用程式檔案。

1. 在**設定測試**下，在**選取測試架構**區段中，選擇**內建：模糊**。

1. 如果系統顯示以下任何設定，您可以接受預設值或指定自己的值：
   + **事件計數**：指定 1 到 10,000 之間的數字，表示模糊測試所要執行的使用者界面事件數。
   + **事件調節**：指定介於 0 到 1，000 之間的數字，表示模糊測試在執行下一個使用者介面事件之前等待的毫秒數。
   + **亂數種子**：指定數字讓模糊測試用於隨機化使用者界面事件。為後續的模糊測試指定相同數字，可確保一致的事件順序。

1. 完成剩餘的說明以選取裝置並開始執行。