

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

# 測試報告許可
<a name="test-permissions"></a>

 本主題說明與測試報告相關的重要許可資訊。

**Topics**
+ [測試報告的 IAM 角色](#test-permissions-required)
+ [測試報告操作的許可](#test-permissions-related-to-reporting)
+ [測試報告許可範例](#test-permissions-examples)

## 測試報告的 IAM 角色
<a name="test-permissions-required"></a>

若要測試執行報告，並更新專案以包含測試報告，您的 IAM 角色需要下列許可。這些許可包含在預先定義的 AWS 受管政策中。如果您想要將測試報告新增至現有的建置專案，您必須自行新增這些許可。
+ `CreateReportGroup` 
+ `CreateReport` 
+ `UpdateReport` 
+ `BatchPutTestCases` 

若要執行程式碼涵蓋範圍報告，您的 IAM 角色也必須包含 `BatchPutCodeCoverages`許可。

**注意**  
`BatchPutTestCases`、`UpdateReport`、 `CreateReport`和 `BatchPutCodeCoverages`不是公有許可。您無法針對這些許可呼叫對應的 AWS CLI 命令或 SDK 方法。

為了確保您擁有這些許可，您可以將下列政策連接至您的 IAM 角色：

```
{
    "Effect": "Allow",
    "Resource": [
        "*"
    ],
    "Action": [
        "codebuild:CreateReportGroup",
        "codebuild:CreateReport",
        "codebuild:UpdateReport",
        "codebuild:BatchPutTestCases",
        "codebuild:BatchPutCodeCoverages"
    ]
}
```

建議您將此政策限制為您必須使用的這些報告群組。在以下範例中，僅限具有政策中兩個 ARN 的報告群組才擁有許可：

```
{
    "Effect": "Allow",
    "Resource": [
        "arn:aws:codebuild:your-region:your-aws-account-id:report-group/report-group-name-1",
        "arn:aws:codebuild:your-region:your-aws-account-id:report-group/report-group-name-2"
    ],
    "Action": [
        "codebuild:CreateReportGroup",
        "codebuild:CreateReport",
        "codebuild:UpdateReport",
        "codebuild:BatchPutTestCases",
        "codebuild:BatchPutCodeCoverages"
    ]
}
```

在以下範例中，僅限在執行名為 `my-project` 之專案的建置時建立的報告群組才擁有許可：

```
{
    "Effect": "Allow",
    "Resource": [
        "arn:aws:codebuild:your-region:your-aws-account-id:report-group/my-project-*"
    ],
    "Action": [
        "codebuild:CreateReportGroup",
        "codebuild:CreateReport",
        "codebuild:UpdateReport",
        "codebuild:BatchPutTestCases",
        "codebuild:BatchPutCodeCoverages"
    ]
}
```

**注意**  
專案中指定的 CodeBuild 服務角色用於上傳到 S3 儲存貯體的許可。

## 測試報告操作的許可
<a name="test-permissions-related-to-reporting"></a>

 您可以指定下列測試報告 CodeBuild API 操作的許可：
+  `BatchGetReportGroups` 
+  `BatchGetReports` 
+  `CreateReportGroup` 
+  `DeleteReportGroup` 
+  `DeleteReport` 
+  `DescribeTestCases` 
+  `ListReportGroups` 
+  `ListReports` 
+  `ListReportsForReportGroup` 
+  `UpdateReportGroup` 

如需詳細資訊，請參閱[AWS CodeBuild 許可參考](auth-and-access-control-permissions-reference.md)。

## 測試報告許可範例
<a name="test-permissions-examples"></a>

 如需與測試報告相關的範例政策資訊，請參閱以下相關資訊：
+  [允許使用者變更報告群組](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-change-report-group) 
+  [允許使用者建立報告群組](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-create-report-group) 
+  [允許使用者刪除報告](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-delete-report) 
+  [允許使用者刪除報告群組](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-delete-report-group) 
+  [允許使用者取得報告群組的相關資訊](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-get-information-about-report-group) 
+  [允許使用者取得報告的相關資訊](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-get-information-about-reports) 
+  [允許使用者取得報告群組的清單](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-get-list-of-report-groups) 
+  [允許使用者取得報告的清單](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-get-list-of-reports) 
+  [允許使用者取得報告群組的報告清單](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-get-list-of-reports-for-report-group) 
+  [允許使用者取得報告的測試案例清單](auth-and-access-control-iam-identity-based-access-control.md#customer-managed-policies-example-get-list-of-test-cases-for-report) 