更新时间:2025-06-26 GMT+08:00
分享

批量更新测试用例结果

功能介绍

批量更新测试用例结果

调用方法

请参见如何调用API

URI

POST /v1/projects/{project_id}/testcases/result

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

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

约束限制:

不涉及

取值范围:

项目uuid应符合如下规则:长度等于32位,包含大小写字母、数字

默认取值:

不涉及

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

表3 请求Body参数

参数

是否必选

参数类型

描述

execute_list

Array of UpdateTestCaseResultBean objects

测试用例状态信息,数组长度小于等于50

service_id

Integer

参数解释:

测试用例类型ID,指定指定对应类型的测试用例ID

约束限制:

需要与execute_list中提供的用例的执行方式一致

取值范围:

大于0整数

默认取值:

不涉及

表4 UpdateTestCaseResultBean

参数

是否必选

参数类型

描述

description

String

参数解释:

用于记录该次结果执行的备注信息

约束限制:

不涉及

取值范围:

长度小于2000字符

默认取值:

不涉及

duration

Long

参数解释:

执行用例持续时长ms

约束限制:

更新状态时该字段必传

取值范围:

大于0整数,单位ms

默认取值:

不涉及

end_time

Long

参数解释:

用例结束执行的时间戳

约束限制:

在执行结束时该字段必传

取值范围:

符合时间戳格式

默认取值:

不涉及

execute_id

String

参数解释:

注册服务执行id

约束限制:

该值不允许重复

取值范围:

长度为1-32位字符(字母或数字)

默认取值:

不涉及

result_id

String

参数解释:

测试用例结果

约束限制:

不涉及

取值范围:

0-成功,1-失败,5-执行中,6-停止

默认取值:

不涉及

testcase_id

String

参数解释:

用例uri,测试用例唯一标识,测试用例详情页面地址栏url https://{host}/cloudtestportal/project/{project_id}/testcase?branch_id={branch_id}&case_id={case_id}&detail=base中case_id变量的值

约束限制:

不涉及

取值范围:

长度11-34位字符(字母和数字)

默认取值:

不涉及

响应参数

状态码:200

表5 响应Body参数

参数

参数类型

描述

status

String

状态

result

result object

结果

表6 result

参数

参数类型

描述

value

String

success/failed

状态码:400

表7 响应Body参数

参数

参数类型

描述

error_code

String

参数解释

接口调用失败错误码

取值范围

不涉及

error_msg

String

参数解释

接口调用失败错误信息

取值范围

不涉及

状态码:401

表8 响应Body参数

参数

参数类型

描述

error_code

String

参数解释

接口调用失败错误码

取值范围

不涉及

error_msg

String

参数解释

接口调用失败错误信息

取值范围

不涉及

状态码:404

表9 响应Body参数

参数

参数类型

描述

error_code

String

参数解释

接口调用失败错误码

取值范围

不涉及

error_msg

String

参数解释

接口调用失败错误信息

取值范围

不涉及

状态码:500

表10 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

接口调用失败错误码

取值范围:

不涉及

error_msg

String

参数解释:

接口调用失败错误信息

取值范围:

不涉及

请求示例

批量更新测试用例结果

post https://{endpoint}/v1/projects/efdb403066474ab08836b9eeaaa23bca/testcases/result

{
  "execute_list" : [ {
    "description" : "这是一条备注信息",
    "duration" : 10,
    "end_time" : 16659743037899,
    "execute_id" : "efdb403066474ab08836b9eeaaa23bca",
    "result_id" : "0",
    "testcase_id" : "b66aab5469cc4ab39b0dda8e644a42a4"
  } ],
  "service_id" : 13
}

响应示例

状态码:200

ok

{
  "status" : "success",
  "result" : {
    "value" : {
      "uri" : "v80b00010i5dji80",
      "type" : "TestCase",
      "author" : "fe2b1b7779a447ee9b650ecc43a18c81",
      "name" : "测试用例3",
      "rank" : 2,
      "stage" : "1",
      "designer" : "fe2b1b7779a447ee9b650ecc43a18c81",
      "region" : "roma-dev-2-arm",
      "issue" : {
        "id" : "1429920",
        "name" : "111111111",
        "path" : "1429920",
        "tracker_name" : "Story"
      },
      "last_modifier" : "fe2b1b7779a447ee9b650ecc43a18c81",
      "last_modified" : "2025-06-19 15:08:16",
      "last_modified_timestamp" : 1750316896000,
      "last_change_time" : "2025-06-16 15:10:25",
      "version_uri" : "v90100010gpop318",
      "parent_uri" : "v90100010gpop318",
      "parent_path" : "/a5eb0d410ea341a192f7c12483568985/v90100010gpop318/",
      "creation_version_uri" : "v90100010gpop318",
      "creation_date" : "2025-06-16 15:10:25",
      "creation_date_timestamp" : 1750057825000,
      "author_name" : "TMSS02",
      "number" : "106",
      "case_type" : 0,
      "platform_type" : 0,
      "service_type" : 0,
      "service_type_name" : "手工测试",
      "test_type" : 0,
      "test_step_model" : "table",
      "test_step" : "[\"1\"]",
      "expect_output" : "[\"1\"]",
      "auto_type" : 0,
      "to_be_auto_exec" : 0,
      "feature_name" : "其他",
      "dr_relation_id" : "1429920",
      "dr_relation_id_list" : [ "1429920" ],
      "automatically_executed" : 0,
      "is_contract_testcase" : 0,
      "time_cost" : 0,
      "last_exe_author" : "fe2b1b7779a447ee9b650ecc43a18c81",
      "status_code" : "7",
      "result_code" : "0",
      "labels" : [ ],
      "execute_latest_time" : "2025-06-19 15:08:16",
      "execute_duration" : "00:00:00.000",
      "execute_times" : 0,
      "is_keyword" : 0,
      "project_uuid" : "a5eb0d410ea341a192f7c12483568985",
      "last_modifier_name" : "fe2b1b7779a447ee9b650ecc43a18c81",
      "issue_list" : [ {
        "id" : "1429920",
        "name" : "111111111",
        "path" : "1429920",
        "tracker_name" : "Story"
      } ],
      "steps" : [ {
        "test_step" : "1",
        "expect_result" : "1"
      } ],
      "feature_abs_path" : "其他",
      "associate_defect" : false,
      "associate_issue" : true,
      "defect_list" : [ {
        "id" : "1429059",
        "name" : "Bug02"
      }, {
        "id" : "1429058",
        "name" : "Bug03"
      }, {
        "id" : "1429057",
        "name" : "新建bug"
      }, {
        "id" : "1429056",
        "name" : "bug001"
      }, {
        "id" : "1429055",
        "name" : "bug002"
      }, {
        "id" : "1429054",
        "name" : "bug003"
      }, {
        "id" : "1429053",
        "name" : "bug004"
      }, {
        "id" : "1429052",
        "name" : "bug005"
      }, {
        "id" : "1429051",
        "name" : "bug006"
      }, {
        "id" : "1429050",
        "name" : "bug007"
      }, {
        "id" : "1429060",
        "name" : "Bug001"
      } ],
      "branch_uri" : "v90100010gpop318",
      "branch_name" : "基线",
      "iterator_uri" : "",
      "iterator_name" : ""
    }
  }
}

状态码:500

Internal Server Error

{
  "error_code" : "CLOUDTEST.00000001",
  "error_msg" : "接口调用失败错误信息"
}

SDK代码示例

SDK代码示例如下。

Java

批量更新测试用例结果

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.cloudtest.v1.region.CloudtestRegion;
import com.huaweicloud.sdk.cloudtest.v1.*;
import com.huaweicloud.sdk.cloudtest.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class UpdateTestCaseResultSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        CloudtestClient client = CloudtestClient.newBuilder()
                .withCredential(auth)
                .withRegion(CloudtestRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateTestCaseResultRequest request = new UpdateTestCaseResultRequest();
        request.withProjectId("{project_id}");
        UpdateTestCaseResultRequestBody body = new UpdateTestCaseResultRequestBody();
        List<UpdateTestCaseResultBean> listbodyExecuteList = new ArrayList<>();
        listbodyExecuteList.add(
            new UpdateTestCaseResultBean()
                .withTestcaseId("b66aab5469cc4ab39b0dda8e644a42a4")
                .withExecuteId("efdb403066474ab08836b9eeaaa23bca")
                .withResultId("0")
                .withEndTime(16659743037899L)
                .withDuration(10L)
                .withDescription("这是一条备注信息")
        );
        body.withExecuteList(listbodyExecuteList);
        body.withServiceId(13);
        request.withBody(body);
        try {
            UpdateTestCaseResultResponse response = client.updateTestCaseResult(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Python

批量更新测试用例结果

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcloudtest.v1.region.cloudtest_region import CloudtestRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcloudtest.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = BasicCredentials(ak, sk)

    client = CloudtestClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CloudtestRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateTestCaseResultRequest()
        request.project_id = "{project_id}"
        listExecuteListbody = [
            UpdateTestCaseResultBean(
                testcase_id="b66aab5469cc4ab39b0dda8e644a42a4",
                execute_id="efdb403066474ab08836b9eeaaa23bca",
                result_id="0",
                end_time=16659743037899,
                duration=10,
                description="这是一条备注信息"
            )
        ]
        request.body = UpdateTestCaseResultRequestBody(
            execute_list=listExecuteListbody,
            service_id=13
        )
        response = client.update_test_case_result(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

批量更新测试用例结果

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    cloudtest "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cloudtest/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cloudtest/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cloudtest/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cloudtest.NewCloudtestClient(
        cloudtest.CloudtestClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateTestCaseResultRequest{}
	request.ProjectId = "{project_id}"
	durationExecuteList:= int64(10)
	descriptionExecuteList:= "这是一条备注信息"
	var listExecuteListbody = []model.UpdateTestCaseResultBean{
        {
            TestcaseId: "b66aab5469cc4ab39b0dda8e644a42a4",
            ExecuteId: "efdb403066474ab08836b9eeaaa23bca",
            ResultId: "0",
            EndTime: int64(16659743037899),
            Duration: &durationExecuteList,
            Description: &descriptionExecuteList,
        },
    }
	request.Body = &model.UpdateTestCaseResultRequestBody{
		ExecuteList: listExecuteListbody,
		ServiceId: int32(13),
	}
	response, err := client.UpdateTestCaseResult(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

ok

400

Bad Request

401

Unauthorized

404

Not Found

500

Internal Server Error

错误码

请参见错误码

相关文档