更新时间:2025-07-25 GMT+08:00
分享

批量创建测试用例

功能介绍

批量创建测试用例

调用方法

请参见如何调用API

URI

POST /v4/testcases/batch-add

请求参数

表1 请求Body参数

参数

是否必选

参数类型

描述

project_uuid

String

项目UUID,项目唯一标识,固定长度32位字符(字母和数字)。获取方式请参见获取项目ID

version_uri

String

分支或者迭代uri

is_ignore

Boolean

是否忽略异常

test_case_infos

Array of CreateTestCaseInfo objects

批量创建用例信息

import_test_case_num

Integer

ApiTest导入用例,分批调用接口时,首次调用接口,校验整个导入用例值,保持手工用例导入规则一致

表2 CreateTestCaseInfo

参数

是否必选

参数类型

描述

steps

Array of TestCaseStepInfo objects

测试步骤

attachments

Array of TestCaseAttachmentInfo objects

附件

author

String

创建人

name

String

名称

rank

Integer

用例等级

owner

String

处理人

preparation

String

前置条件

remark

String

备注

stage

String

测试阶段

activity

String

测试类型

keywords

String

关键词

market

String

apitest标记是否代码已提交

designer

String

设计者

tags

String

标签

region

String

逻辑region,外部使用公有云实际区域,内部使用默认值

uri

String

测试用例Uri

relate_type

String

关联资源类型

service_type

Integer

服务类型

only_change_script

String

关联资源类型只更新接口用例的java脚本路径标识

add_to_iterator

String

需求添加到迭代标识

need_update_relation

String

是否修改关联关系

creation_version_uri

String

创建版本Uri

number

String

用例编号

case_type

Integer

用例类型

platform_type

Integer

执行平台类型

test_type

Integer

测试类型

design_note

String

设计描述

test_step

String

测试步骤

expect_output

String

期望结果

env_type

String

测试环境类型

exe_platform

String

执行平台

testcase_project

String

测试工程

svn_script_path

String

脚本路径

map_restrict

String

约束条件

network_script_name

String

网络脚本名

auto_type

Integer

自动化类型,非自动化:0, 是自动化:1

to_be_auto_exec

Integer

被自动化执行

last_result

String

最后一次结果

last_result_uri

String

最后一次结果Uri

feature_uri

String

目录Uri

interface_name

String

测试接口名

snp_no

String

网络问题ID

dr_relation_id

String

关联需求编号

test_base_num

String

测试基数

automatically_executed

Integer

是否被自动化执行

first_execute_time

String

第一次执行时间

detect_type

String

检测类型

execute_param

String

执行参数

test_feature

String

分析领域

is_contract_testcase

Integer

是否是契约用例,0:表示非契约用例, 1:表示契约用例

time_cost

Double

总共耗时

custom_field_1

String

自定义字段1

custom_field_2

String

自定义字段2

custom_field_3

String

自定义字段3

custom_field_4

String

自定义字段4

custom_field_5

String

自定义字段5

custom_field_6

String

自定义字段6

custom_field_7

String

自定义字段7

custom_field_8

String

自定义字段8

custom_field_9

String

自定义字段9

custom_field_10

String

自定义字段10

custom_field_11

String

自定义字段11

custom_field_12

String

自定义字段12

custom_field_13

String

自定义字段13

custom_field_14

String

自定义字段14

custom_field_15

String

自定义字段15

custom_field_16

String

自定义字段16

custom_field_17

String

自定义字段17

custom_field_18

String

自定义字段18

custom_field_19

String

自定义字段19

custom_field_20

String

自定义字段20

custom_field_21

String

自定义字段21

custom_field_22

String

自定义字段22

custom_field_23

String

自定义字段23

custom_field_24

String

自定义字段24

custom_field_25

String

自定义字段25

be_auto_type_time

String

记录用例由非自动化变为自动化类型的时间

compare_number

String

配对用例编号

scene_flag

String

场景标识

base_flag

String

场景标识

para_validator

String

区别是否从yaml中生成的用例,默认false

knet_node_id

String

knet节点id

last_exe_author

String

最后一次执行用户

cloud_carrier

String

运营商

market_place

String

应用市场

test_mind_id

String

脑图id

test_mind_url

String

脑图url

commit_url

String

git提交url

test_pattern_number

String

测试模式编号

test_factor_number

String

测试因子编号

status_code

String

状态Code

result_code

String

结果Code

release_id

String

迭代ID

label_id

String

标签ID

label_names

Array of strings

用例操作时,标签名列表

module_id

String

模块ID

execute_latest_time

String

最后执行时间

execute_duration

String

执行时长

is_keyword

Integer

是否关键用例

release_dev

String

测试版本号

new_created

Integer

是否用户新增用例

execute_parameter

String

执行参数

project_id

String

项目UUID,项目唯一标识,固定长度32位字符(字母和数字)。获取方式请参见获取项目ID

version_uri

String

分支或者迭代uri

external_test_case_id

String

外部用例id

表3 TestCaseStepInfo

参数

是否必选

参数类型

描述

test_step

String

测试步骤

expect_result

String

预期结果

step_actual

String

步骤的实际结果

step_result

String

步骤结果

表4 TestCaseAttachmentInfo

参数

是否必选

参数类型

描述

override

Boolean

附件是否要被覆盖

doc_id

String

文档id

file_name

String

文件名

file_path

String

文件路径

file_type

String

文件类型

file_size

String

文件大小

override_id

String

重复用例ID

related_type

String

相关类型

store_file_name

String

保存文件名

system_type

String

系统区分

storage_system

String

区分文件存储系统

响应参数

状态码:200

表5 响应Body参数

参数

参数类型

描述

status

String

success|error

result

ResultValueBatchCreateTestCaseVo object

批量创建测试用例返回参数

error

ApiError object

错误信息

request_id

String

由接口调用方传入,建议使用UUID保证请求的唯一性。

server_address

String

本次请求的受理的服务地址

表6 ResultValueBatchCreateTestCaseVo

参数

参数类型

描述

total

Integer

起始记录数 大于 实际总条数时, 值为0, 分页请求才有此值

value

BatchCreateTestCaseVo object

请求返回的数据对象

reason

String

业务失败的提示内容

page_size

Integer

分页大小

page_no

Integer

分页编码

has_more

Boolean

是否有更多

表7 BatchCreateTestCaseVo

参数

参数类型

描述

success

Array of CreateTestCaseVo objects

批量用例创建成功信息

failed

Array of ValidateExceptionVo objects

批量用例创建失败信息

表8 CreateTestCaseVo

参数

参数类型

描述

uri

String

资源URI

type

String

资源类型

author

String

创建人

name

String

名称

rank

Integer

级别

preparation

String

前置条件

remark

String

备注

stage

String

测试阶段

activity

String

测试类型

keywords

String

关键词

market

String

apitest标记是否代码已提交

designer

String

设计者

tags

String

标签

execute_parameter

String

执行参数

region

String

逻辑region

owner

String

处理人id,IteratorTestCase字段

last_modifier

String

最后修改人

last_modified

String

最后修改时间

last_modified_timestamp

Long

修改时间时间戳

last_change_time

String

最后变更时间

version_uri

String

版本URI

origin_uri

String

源资源URI

parent_uri

String

父资源URI

parent_path

String

父资源路径

creation_version_uri

String

创建版本URI

creation_date

String

创建时间

creation_date_timestamp

Long

创建时间时间戳

author_name

String

创建人名称

comment

String

备注

number

String

编号

case_type

Integer

用例类型

platform_type

Integer

执行平台类型

service_type

Integer

服务类型

service_type_name

String

服务类型名称

test_type

Integer

测试类型

test_type_name

String

测试类型名称

design_note

String

设计描述

test_step

String

测试步骤

expect_output

String

期望结果

env_type

String

测试环境类型

exe_platform

String

执行平台

testcase_project

String

测试工程

svn_script_path

String

脚本路径

map_restrict

String

约束条件

network_script_name

String

网络脚本名

auto_type

Integer

自动化类型,非自动化:0, 是自动化:1

to_be_auto_exec

Integer

被自动化执行

last_result

String

最后一次结果

last_result_uri

String

最后一次结果Uri

feature_uri

String

目录Uri

feature_name

String

目录名称

interface_name

String

测试接口名

snp_no

String

网络问题ID

dr_relation_id

String

关联需求编号

issue_name

String

需求名称

test_base_num

String

测试基数

automatically_executed

Integer

是否被自动化执行

first_execute_time

String

第一次执行时间

detect_type

String

检测类型

execute_param

String

执行参数

test_feature

String

分析领域

is_contract_testcase

Integer

是否是契约用例,0:表示非契约用例, 1:表示契约用例

time_cost

Double

总共耗时

be_auto_type_time

String

记录用例由非自动化变为自动化类型的时间

compare_number

String

配对用例编号

scene_flag

String

场景标识

base_flag

String

场景标识

para_validator

String

区别是否从yaml中生成的用例,默认false

knet_node_id

String

knet节点id

last_exe_author

String

最后一次执行用户

cloud_carrier

String

运营商

market_place

String

应用市场

test_mind_id

String

脑图id

test_mind_url

String

脑图url

commit_url

String

git提交url

test_pattern_number

String

测试模式编号

test_factor_number

String

测试因子编号

status_code

String

状态Code

result_code

String

结果Code

release_id

String

迭代ID

label_id

String

标签ID

labels

String

用例标签名称列表

module_id

String

模块ID

module_name

String

模块名称

module_path

String

模块path

module_path_name

String

模块路径名称

execute_latest_time

String

最后执行时间

execute_duration

String

执行时长

execute_times

Integer

执行次数

is_keyword

Integer

是否关键用例

release_dev

String

测试版本号

new_created

String

是否用户新增用例

project_id

String

项目UUID,项目唯一标识,固定长度32位字符(字母和数字)。获取方式请参见获取项目ID

creation_version_name

String

创建版本名称,原逻辑marshall添加字段

feature_path

String

特性路径,原逻辑marshall添加字段

testcase_uri

String

实体用例Uri,IteratorTestCase字段

owner_name

String

处理人名称

iterator_case_uri

String

迭代用例Uri,IteratorTestCase字段

script_link

String

脚本链接scriptLink

custom_field_1

String

自定义字段1

custom_field_2

String

自定义字段2

custom_field_3

String

自定义字段3

custom_field_4

String

自定义字段4

custom_field_5

String

自定义字段5

custom_field_6

String

自定义字段6

custom_field_7

String

自定义字段7

custom_field_8

String

自定义字段8

custom_field_9

String

自定义字段9

custom_field_10

String

自定义字段10

custom_field_11

String

自定义字段11

custom_field_12

String

自定义字段12

custom_field_13

String

自定义字段13

custom_field_14

String

自定义字段14

custom_field_15

String

自定义字段15

custom_field_16

String

自定义字段16

custom_field_17

String

自定义字段17

custom_field_18

String

自定义字段18

custom_field_19

String

自定义字段19

custom_field_20

String

自定义字段20

custom_field_21

String

自定义字段21

custom_field_22

String

自定义字段22

custom_field_23

String

自定义字段23

custom_field_24

String

自定义字段24

custom_field_25

String

自定义字段25

external_test_case_id

String

外部用例id

project_uuid

String

项目id

表9 ValidateExceptionVo

参数

参数类型

描述

external_testcase_id

String

外部用例id,用于apitest匹配错误用例

error_content

String

错误信息的唯一标识,取决于错误记录中哪个字段可以直观体现是哪个错误记录

error_field

String

错误字段

error_msg

String

错误内容

error_code

String

错误码

表10 ApiError

参数

参数类型

描述

code

String

业务失败的错误编码

reason

String

业务失败的提示内容

状态码:400

表11 响应Body参数

参数

参数类型

描述

error_code

String

接口调用失败错误码

error_msg

String

接口调用失败错误信息

状态码:401

表12 响应Body参数

参数

参数类型

描述

error_code

String

接口调用失败错误码

error_msg

String

接口调用失败错误信息

状态码:404

表13 响应Body参数

参数

参数类型

描述

error_code

String

接口调用失败错误码

error_msg

String

接口调用失败错误信息

状态码:500

表14 响应Body参数

参数

参数类型

描述

error_code

String

接口调用失败错误码

error_msg

String

接口调用失败错误信息

请求示例

post https://{endpoint}/v4/testcases/batch-add

{
  "version_uri" : "v90200010aelu5om",
  "test_case_infos" : [ {
    "steps" : [ {
      "test_step" : "",
      "expect_result" : ""
    } ],
    "test_mind_id" : "41047aa57b6246fd97b8cdf049e17c86",
    "name" : "sdsdsdsd",
    "rank" : "2",
    "preparation" : "",
    "remark" : "",
    "service_type" : "0",
    "external_test_case_id" : "C2E9C88A7E194490A0750AF5ED93811B",
    "feature_uri" : "407ac57de7ea44d28e47293a2b9cf15c",
    "owner" : "2ce06fffb4634271a377c1cd7c429704",
    "relate_type" : "requirement"
  } ]
}

响应示例

状态码:200

OK

{
  "status" : "success",
  "result" : {
    "value" : {
      "success" : [ {
        "uri" : "v90100010i5o9atn",
        "type" : "TestCase",
        "author" : "2ce06fffb4634271a377c1cd7c429704",
        "name" : "sdsdsdsd",
        "rank" : 2,
        "stage" : "1",
        "designer" : "2ce06fffb4634271a377c1cd7c429704",
        "region" : "roma-dev-2-arm",
        "owner" : "2ce06fffb4634271a377c1cd7c429704",
        "last_modifier" : "2ce06fffb4634271a377c1cd7c429704",
        "last_modified" : "2025-06-16 18:17:04",
        "last_change_time" : "2025-06-16 18:17:04",
        "version_uri" : "v90200010aelu5om",
        "parent_uri" : "v90200010aelu5om",
        "parent_path" : "/407ac57de7ea44d28e47293a2b9cf15c/v90200010aelu5om/",
        "creation_date" : "2025-06-16 18:17:04",
        "number" : "7428",
        "case_type" : 0,
        "platform_type" : 0,
        "service_type" : 0,
        "test_type" : 0,
        "external_test_case_id" : "C2E9C88A7E194490A0750AF5ED93811B",
        "test_step" : "[\"\"]",
        "expect_output" : "[\"\"]",
        "auto_type" : 0,
        "to_be_auto_exec" : 0,
        "automatically_executed" : 0,
        "is_contract_testcase" : 0,
        "time_cost" : 0,
        "test_mind_id" : "41047aa57b6246fd97b8cdf049e17c86",
        "status_code" : "0",
        "execute_times" : 0
      } ],
      "failed" : [ ]
    }
  }
}

状态码

状态码

描述

200

OK

400

Bad Request

401

Unauthorized

404

Not Found

500

Internal Server Error

错误码

请参见错误码

相关文档