

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

# test-e2e
<a name="greengrass-development-kit-cli-test"></a>

使用 AWS IoT Greengrass 開發套件命令列界面 (GDK CLI) 中的 `test-e2e`命令，在 GDK 專案中初始化、建置和執行end-to-end測試模組。

**Topics**
+ [init](#greengrass-development-kit-cli-test-init)
+ [build](#greengrass-development-kit-cli-test-build)
+ [run](#greengrass-development-kit-cli-test-run)

## init
<a name="greengrass-development-kit-cli-test-init"></a>

使用使用 Greengrass 測試架構 (GTF) 的測試模組初始化現有的 GDK CLI 專案。

根據預設，GDK CLI 會從 [AWS IoT Greengrass GitHub 上的元件範本儲存庫擷取數學模組範本](https://github.com/aws-greengrass/aws-greengrass-component-templates)。此 maven 模組隨附 `aws-greengrass-testing-standalone` JAR 檔案的相依性。

此命令會在 GDK 專案`gg-e2e-tests`內建立新的目錄，稱為 。如果測試模組目錄已存在且不是空的，則命令會結束而不執行任何動作。此`gg-e2e-tests`資料夾包含在 maven 專案中建構的 Cucumber 功能和步驟定義。

根據預設，此命令會嘗試使用最新版本的 GTF。

**概要**  

```
$ gdk test-e2e init
    [--gtf-version]
```

**Arguments (引數)**  
+ `-ov`、 `--gtf-version` – （選用） GTF 的版本，用於 GDK 專案中的end-to-end測試模組。此值必須是版本中的[其中一個 GTF ](https://github.com/aws-greengrass/aws-greengrass-testing/releases)版本。此引數會覆寫 GDK CLI 組態`gtf_version`中的 。

**輸出**  
下列範例顯示執行此命令以使用測試模組初始化 GDK 專案時產生的輸出。  

```
$ gdk test-e2e init
[2023-12-06 12:20:28] INFO - Using the GTF version provided in the GDK test config 1.2.0
[2023-12-06 12:20:28] INFO - Downloading the E2E testing template from GitHub into gg-e2e-tests directory...
```

## build
<a name="greengrass-development-kit-cli-test-build"></a>

**注意**  
您必須先執行 來建置元件，**gdk component build**end-to-end測試模組。

建置end-to-end測試模組。GDK CLI 會使用您在 `test-e2e` 屬性下的 [GDK CLI 組態檔案中](gdk-cli-configuration-file.md)指定的建置系統`gdk-config.json`來建置測試模組。您必須在`gdk-config.json`檔案存在的相同資料夾中執行此命令。

根據預設，GDK CLI 會使用 maven 建置系統來建置測試模組。執行 `gdk test-e2e build`命令需要 [Maven](https://maven.apache.org/)。

如果測試功能檔案具有 `GDK_COMPONENT_NAME`和 等變數`GDK_COMPONENT_RECIPE_FILE`來插補，則必須先執行 來建置元件，**gdk-component-build**才能建置測試模組。

當您執行此命令時，GDK CLI 會從 GDK 專案組態插入所有變數，並建置`gg-e2e-tests`模組以產生最終測試 JAR 檔案。

**概要**  

```
$ gdk test-e2e build
```

**Arguments (引數)**  
無

**輸出**  
下列範例顯示執行此命令時產生的輸出。  

```
$ gdk test-e2e build
[2023-07-20 15:36:48] INFO - Updating feature file: file:///path/to//HelloWorld/greengrass-build/gg-e2e-tests/src/main/resources/greengrass/features/component.feature
[2023-07-20 15:36:48] INFO - Creating the E2E testing recipe file:///path/to/HelloWorld/greengrass-build/recipes/e2e_test_recipe.yaml
[2023-07-20 15:36:48] INFO - Building the E2E testing module
[2023-07-20 15:36:48] INFO - Running the build command 'mvn package'
.........
```

## run
<a name="greengrass-development-kit-cli-test-run"></a>

使用 GDK 組態檔案中的測試選項執行測試模組。

**注意**  
您必須先執行 來建置測試模組，**gdk test-e2e build**end-to-end測試。

**概要**  

```
$ gdk test-e2e run
    [--gtf-options]
```

**Arguments (引數)**  
+ `-oo`， `--gtf-options` – （選用） 指定執行end-to-end測試的選項清單。引數必須是有效的 JSON 字串或包含 GTF 選項的 JSON 檔案路徑。組態檔案中提供的選項會與命令引數中提供的選項合併。如果兩個位置都有 選項，則引數中的一個會比組態檔案中的某個選項有前置。

  如果此命令中未指定 `tags`選項，則 GDK 會使用 `Sample`進行標籤。如果`ggc-archive`未指定 ，則 GDK 會下載最新版本的 Greengrass 核封存。

**輸出**  
下列範例顯示執行此命令時產生的輸出。  

```
$ gdk test-e2e run
[2023-07-20 16:35:53] INFO - Downloading latest nucleus archive from url https://d2s8p88vqu9w66.cloudfront.net/releases/greengrass-latest.zip
[2023-07-20 16:35:57] INFO - Running test jar with command java -jar /path/to/greengrass-build/gg-e2e-tests/target/uat-features-1.0.0.jar —ggc-archive=/path/to/aws-greengrass-gdk-cli/HelloWorld/greengrass-build/greengrass-nucleus-latest.zip —tags=Sample

16:35:59.693 [] [] [] [INFO] com.aws.greengrass.testing.modules.GreengrassContextModule - Extracting /path/to/workplace/aws-greengrass-gdk-cli/HelloWorld/greengrass-build/greengrass-nucleus-latest.zip into /var/folders/7g/ltzcb_3s77nbtmkzfb6brwv40000gr/T/gg-testing-7718418114158172636/greengrass
16:36:00.534 [gtf-1.1.0-SNAPSHOT] [] [] [INFO] com.aws.greengrass.testing.features.LoggerSteps - GTF Version is gtf-1.1.0-SNAPSHOT
.......
```