0

我在 Azure TFS 中通过 python 中的 POST 方法自动创建测试计划时遇到问题。当我在 UI 中手动创建它时,一切正常,当我尝试找到这个工作项时,例如。http://xxx/tfs/test/Project/_apis/test/plans/266801?api-version=5.0- 一切正常,我得到 JSON。

我的代码:

def TestPlan(title=None, description=None):
    def wrapper(func):
        def inner_wrapper(*args, **kwargs):
            authorization = str(base64.b64encode(bytes(':' + token, 'ascii')), 'ascii')
            headers = {
                'Content-Type': 'application/json-patch+json',
                'Authorization': 'Basic ' + authorization
            }
            URL = url + '/' + project + '/_apis/wit/workitems/$Test Plan?' + api_version
            body = [
                {
                    "op": "add",
                    "path": "/fields/System.Title",
                    "value": title
                },
                {
                    "path": "/fields/System.Description",
                    "op": "add",
                    "value": description
                },
                {
                    "path": "/fields/Microsoft.VSTS.TCM.AutomatedTestId",
                    "op": "add",
                    "value": automationId(func)
                }
            ]
            requests.post(URL, json=body, headers=headers)
            func(*args, **kwargs)
        return inner_wrapper
    return wrapper

当我使用我的代码时,会创建工作项,但仅在 UI 中。当我尝试在 API 中找到它时,出现错误: {"$id":"1","innerException":null,"message":"Test plan 266800 not found.","typeName":"Microsoft.TeamFoundation.TestManagement.WebApi.TestObjectNotFoundException, Microsoft.TeamFoundation.TestManagement.WebApi","typeKey":"TestObjectNotFoundException","errorCode":0,"eventId":3000} 当我在 UI 中单击此工作项时,我有这个: 天蓝色测试计划错误 我想我需要在创建测试计划期间添加一个 rootSuite,但是该怎么做呢?你可以帮帮我吗?

4

1 回答 1

1

为什么要使用工作项 API 来创建测试计划 ( _apis/wit/workitems)?

您必须使用测试计划 API ( _apis/testplan/plans)。以下是示例:测试计划 - 创建

于 2021-02-18T14:55:04.843 回答