

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

# 檢閱 IDT 測試結果和日誌
<a name="idt-review-results-logs"></a>

本節說明 IDT 產生主控台日誌和測試報告的格式。

## 主控台訊息格式
<a name="idt-console-format"></a>

AWS IoT Device Tester 使用標準格式，在 主控台啟動測試套件時，將訊息列印到 主控台。以下摘錄顯示 IDT 產生的主控台訊息範例。

```
time="2000-01-02T03:04:05-07:00" level=info msg=Using suite: MyTestSuite_1.0.0 
executionId=9a52f362-1227-11eb-86c9-8c8590419f30
```

大多數主控台訊息包含下列欄位：

`time`  
已記錄事件的完整 ISO 8601 時間戳記。

`level`  
已記錄事件的訊息層級。一般而言，記錄的訊息層級是 `info`、 `warn`或 之一`error`。如果 IDT 遇到預期事件導致提早結束，則發出 `fatal`或 `panic` 訊息。

`msg`  
記錄的訊息。

`executionId`  
目前 IDT 程序的唯一 ID 字串。此 ID 用於區分個別 IDT 執行。

從測試套件產生的主控台訊息提供有關受測裝置以及 IDT 執行的測試套件、測試群組和測試案例的其他資訊。以下摘錄顯示從測試套件產生的主控台訊息範例。

```
time="2000-01-02T03:04:05-07:00" level=info msg=Hello world! suiteId=MyTestSuite
groupId=myTestGroup testCaseId=myTestCase deviceId=my-device
executionId=9a52f362-1227-11eb-86c9-8c8590419f30
```

主控台訊息的測試套件特定部分包含下列欄位：

`suiteId`  
目前正在執行的測試套件名稱。

`groupId`  
目前正在執行的測試群組 ID。

`testCaseId`  
目前執行的測試案例 ID。

`deviceId`  
目前測試案例正在使用的測試中裝置的 ID。

若要在 IDT 完成執行測試時將測試摘要列印到主控台，您必須在測試協調器中包含 [`Report` 狀態](idt-state-machine.md#state-report)。測試摘要包含測試套件的相關資訊、執行的每個群組的測試結果，以及產生的日誌和報告檔案的位置。下列範例顯示測試摘要訊息。

```
========== Test Summary ==========
Execution Time:     5m00s
Tests Completed:    4
Tests Passed:       3
Tests Failed:       1
Tests Skipped:      0
----------------------------------
Test Groups:
    GroupA:         PASSED
    GroupB:         FAILED
----------------------------------
Failed Tests:
    Group Name: GroupB
        Test Name: TestB1
            Reason: Something bad happened
----------------------------------
Path to IoT Device Tester Report: /path/to/awsiotdevicetester_report.xml
Path to Test Execution Logs: /path/to/logs
Path to Aggregated JUnit Report: /path/to/MyTestSuite_Report.xml
```

## AWS IoT Device Tester 報告結構描述
<a name="idt-report"></a>

 `awsiotdevicetester_report.xml` 是已簽章的報告，其中包含下列資訊：
+ IDT 版本。
+ 測試套件版本。
+ 用於簽署報告的報告簽章和金鑰。
+ `device.json` 檔案中指定的裝置 SKU 和裝置集區名稱。
+ 已測試的產品版本和裝置功能。
+ 測試結果的彙總摘要。此資訊與 `suite-name_report.xml` 檔案中包含的資訊相同。

```
<apnreport>
    <awsiotdevicetesterversion>idt-version</awsiotdevicetesterversion>
    <testsuiteversion>test-suite-version</testsuiteversion>
    <signature>signature</signature>
    <keyname>keyname</keyname>
    <session>
        <testsession>execution-id</testsession>
        <starttime>start-time</starttime>
        <endtime>end-time</endtime>
    </session>
    <awsproduct>
        <name>product-name</name>
        <version>product-version</version>
        <features>
            <feature name="<feature-name>" value="supported | not-supported | <feature-value>" type="optional | required"/>
        </features>
    </awsproduct>
    <device>
        <sku>device-sku</sku>
        <name>device-name</name>
        <features>
            <feature name="<feature-name>" value="<feature-value>"/>
        </features>
        <executionMethod>ssh | uart | docker</executionMethod>
    </device>
    <devenvironment>
        <os name="<os-name>"/>
    </devenvironment>
    <report>
        <suite-name-report-contents>
    </report>
</apnreport>
```

`awsiotdevicetester_report.xml` 檔案包含 `<awsproduct>` 標籤，其中包含關於受測產品和經過一系列測試驗證後之產品功能的資訊。`<awsproduct>` 標籤中使用的屬性

`name`  
受測產品名稱。

`version`  
受測產品版本。

`features`  
驗證的功能。測試套件`required`需要標記為 的功能，才能驗證裝置。以下片段顯示此資訊如何出現在 `awsiotdevicetester_report.xml` 檔案中。  

```
<feature name="ssh" value="supported" type="required"></feature>
```
標記為 的功能`optional`不需要驗證。以下程式碼片段顯示選用功能。  

```
<feature name="hsi" value="supported" type="optional"></feature> 
<feature name="mqtt" value="not-supported" type="optional"></feature>
```

## 測試套件報告結構描述
<a name="suite-report"></a>

`suite-name_Result.xml` 報告採用 [JUnit XML 格式](https://llg.cubic.org/docs/junit/)。您可以將它整合到持續整合和部署平台，例如 [Jenkins](https://jenkins.io/)、[Bamboo](https://www.atlassian.com/software/bamboo) 等。報告包含測試結果的彙總摘要。

```
<testsuites name="<suite-name> results" time="<run-duration>" tests="<number-of-test>" failures="<number-of-tests>" skipped="<number-of-tests>" errors="<number-of-tests>" disabled="0">
    <testsuite name="<test-group-id>" package="" tests="<number-of-tests>" failures="<number-of-tests>" skipped="<number-of-tests>" errors="<number-of-tests>" disabled="0">
        <!--success-->
        <testcase classname="<classname>" name="<name>" time="<run-duration>"/>
        <!--failure-->
        <testcase classname="<classname>" name="<name>" time="<run-duration>">
            <failure type="<failure-type>">
                reason
            </failure>
        </testcase>
        <!--skipped-->
        <testcase classname="<classname>" name="<name>" time="<run-duration>">
            <skipped>
                reason
            </skipped>
        </testcase>
        <!--error-->
        <testcase classname="<classname>" name="<name>" time="<run-duration>">
            <error>
                reason
            </error>
        </testcase>
    </testsuite>
</testsuites>
```

`awsiotdevicetester_report.xml` 或 中的報告區段會`suite-name_report.xml`列出已執行的測試和結果。

第一個 XML 標籤 `<testsuites>` 包含測試執行的摘要。例如：

```
<testsuites name="MyTestSuite results" time="2299" tests="28" failures="0" errors="0" disabled="0">
````<testsuites>` 標籤中使用的屬性

`name`  
測試套件的名稱。

`time`  
執行測試套件所需的時間，以秒為單位。

`tests`  
執行的測試次數。

`failures`  
已執行但未通過的測試次數。

`errors`  
IDT 無法執行的測試次數。

`disabled`  
此屬性未使用，可忽略。

如果測試發生失敗或錯誤，您可以檢閱 `<testsuites>` XML 標籤來識別失敗的測試。`<testsuites>` 標籤內的 `<testsuite>` XML 標籤會顯示測試群組的測試結果摘要。例如：

```
<testsuite name="combination" package="" tests="1" failures="0" time="161" disabled="0" errors="0" skipped="0">
```

其格式類似於 `<testsuites>` 標籤，但有不使用且可忽略的 `skipped` 屬性。在每個 `<testsuite>` XML 標籤內，測試群組每個執行的測試都有 `<testcase>` 標籤。例如：

```
<testcase classname="Security Test" name="IP Change Tests" attempts="1"></testcase>>
````<testcase>` 標籤中使用的屬性

`name`  
測試的名稱。

`attempts`  
IDT 執行測試案例的次數。

當測試案例失敗或發生錯誤時，系統就會將 `<failure>` 或 `<error>` 標籤新增至 `<testcase>` 標籤，其中附有相關資訊以利故障診斷。例如：

```
<testcase classname="mcu.Full_MQTT" name="MQTT_TestCase" attempts="1">
	<failure type="Failure">Reason for the test failure</failure>
	<error>Reason for the test execution error</error>
</testcase>
```