
# 用例和用例脚本 - CreateTestCaseAndScriptTwo
#### 功能介绍
根据工程唯一标识和用例脚本信息创建用例
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-testman/cloudtest_03_2000.html)。
#### URI
POST /v2/{project_id}/testcase
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
|:---|:---|:---|:---|
| project_id | 是    | String | **参数解释**: 项目UUID，项目唯一标识，固定长度32位字符（字母和数字）。获取方式请参见[获取项目ID](https://support.huaweicloud.com/api-testman/cloudtest_03_4003.html) **约束限制**: 不涉及 **取值范围**: 项目uuid应符合如下规则：长度等于32位字符，包含大小写字母、数字 **默认取值**: 不涉及 |
   
表2Query参数 
| 参数           | 是否必选 | 参数类型   | 描述    |
|:---|:---|:---|:---|
| iterator_uri | 否    | String | 迭代uri |
   
#### 请求参数
表3请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | **参数解释：** 用户Token。 通过调用IAM服务[获取用户Token](https://support.huaweicloud.com/api-iam/iam_30_0001.html)接口获取（响应消息头中X-Subject-Token的值）。 **约束限制：** 必传。 **取值范围：** 字符串长度不少于1，不超过10万。 **默认取值：** 不涉及。 |
   
表4请求Body参数 
| 参数                                    | 是否必选 | 参数类型   | 描述     |
|:---|:---|:---|:---|
| CreateTestCaseAndScriptTwoRequestBody | 否    | String | 用例脚本信息 |
   
#### 响应参数
**状态码：200**
表5响应Body参数 
| 参数     | 参数类型                                                                                                    | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
|:---|:---|:---|
| error  | [CommonResponseErrorOfobject] object | **参数解释** 统一错误返回 **取值范围** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                  |
| reason | String                                                                                                  | **参数解释** 接口调用失败原因 **取值范围** 不超过1000个字符组成的字符串                                                                                                                                                                                                                                                                                                                                                                                                   |
| result | Object                                                                                                  | **参数解释** 结果 **取值范围** 不涉及                                                                                                                                                                                                                                                                                                                                                                                                                      |
| status | String                                                                                                  | **参数解释** '状态值，如success、error' **取值范围** - success，请求成功   - error，请求报错    |
   
 表6CommonResponseErrorOfobject 
| 参数     | 参数类型   | 描述                                                                                                                                                                                    |
|:---|:---|:---|
| code   | String | **参数解释** 接口调用失败错误码 **取值范围** 不超过256个字符组成的字符串 |
| reason | String | **参数解释** 接口调用失败原因 **取值范围** 不超过1000个字符组成的字符串 |
   
#### 请求示例
```
"{
  "name": "TC_ZPduq",
  "script_name": "TC_ZPduq",
  "releaseDev": "",
  "tmss_case_uri": "",
  "activity_id": 1,
  "tmss_property": {
      "name": "TC_ZPduq",
      "description": "",
      "preparation": "",
      "steps": [
          {
              "testStep": "",
              "expectResult": ""
          }
      ],
      "number": "",
      "level": "2",
      "moduleId": "",
      "releaseDev": "",
      "releaseId": "",
      "ownerId": "",
      "test_type": 1,
      "labelId": [],
      "exe_platform": "apitest"
  },
  "import_info_list": [],
  "case_variable_list": [],
  "aw_instance": {
      "setup_aw_list": [],
      "test_aw_list": [],
      "teardown_aw_list": []
  },
  "source": "cloudtest"
}"
```
#### 响应示例
**状态码：200**
SUCCESS
```
{
  "status" : "success",
  "result" : {
    "id" : "ff9f737472a14508a971192adba88299",
    "name" : "123",
    "deleteFlag" : null,
    "changeSign" : 0,
    "planId" : null,
    "issueId" : "",
    "addToPlan" : null,
    "releaseDev" : "",
    "copyFlag" : false,
    "source" : "cloudtest",
    "region" : "{region}",
    "status" : null,
    "create_time_string" : "2024-07-04 15:02:55 GMT+08:00",
    "update_time_string" : "2024-07-04 15:02:55",
    "create_time_stamp" : 1720076575000,
    "update_time_stamp" : 1720076575000,
    "create_user" : "devcloud_devcloud_s00314720_01",
    "create_time" : "2024-07-04T03:02:55+0800",
    "update_user" : "devcloud_devcloud_s00314720_01",
    "update_time" : "2024-07-04T03:02:55+0800",
    "tmss_property" : {
      "name" : "123",
      "description" : "",
      "number" : "102",
      "cataId" : null,
      "labelId" : [ ],
      "tags" : null,
      "level" : 2,
      "preparation" : "",
      "market" : null,
      "remark" : null,
      "originUri" : null,
      "releaseDev" : "",
      "stage" : null,
      "moduleId" : "",
      "releaseId" : "",
      "uri" : null,
      "node_name" : null,
      "test_type" : 1,
      "testStep" : null,
      "test_step" : null,
      "expectOutput" : null,
      "expect_output" : null,
      "env_type" : null,
      "exe_platform" : "apitest",
      "auto_type" : "1",
      "is_contract_testcase" : null,
      "is_paraValidator_testcase" : null,
      "test_feature" : null,
      "last_modified" : null,
      "last_modifier" : null,
      "author" : null,
      "creation_date" : null,
      "activity_id" : null,
      "owner" : null,
      "feature_path" : null,
      "ownerId" : "",
      "dr_relationid" : null,
      "applied_product" : null,
      "last_result" : null,
      "isKeyWord" : null,
      "steps" : [ {
        "testStep" : "",
        "expectResult" : ""
      } ],
      "networkScriptName" : null,
      "svnScriptPath" : null
    },
    "project_id" : "b7cb42f3fec14acba074624ddccd30db",
    "logic_case_id" : null,
    "activity_id" : "1",
    "package_name" : "scripts.user",
    "script_name" : "Case_ff9f737472a14508a971192adba88299_1",
    "script_path" : "src/scripts/user/Case_ff9f737472a14508a971192adba88299_1.java",
    "tmss_case_uri" : "v91k0000vm7tgc0c",
    "aw_instance" : {
      "setup_aw_list" : [ ],
      "test_aw_list" : [ ],
      "teardown_aw_list" : [ ]
    },
    "case_variable_list" : [ ],
    "quality_check_time" : null,
    "quality_check_result" : null,
    "tc_comments" : null,
    "import_info_list" : [ ],
    "IteratorCaseUri" : null,
    "IsKeyWord" : 0,
    "keyword_id" : null,
    "all_variable_names" : null,
    "variableGroupId" : null,
    "error_step" : null,
    "import_edit" : 5,
    "user_id" : null,
    "case_type" : 0
  },
  "reason" : null,
  "error" : null
}
```
#### 状态码
| 状态码 | 描述      |
|:---|:---|
| 200 | SUCCESS |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-testman/ErrorCode.html)。
