使用 python 在 Azure TFS 中自动创建测试计划

问题描述

我在通过 python 中的 POST 方法在 Azure TFS 中自动创建测试计划时遇到问题。 当我手动创建它时,在 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","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 中点击这个工作项时,我有这个:

azure test plan error

我想我需要在创建测试计划期间添加一个 rootSuite,但是怎么做呢? 你能帮我吗?

解决方法

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

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