首页 > 解决方案 > 如何使用 API/端点更新 VSTS/Microsoft 测试管理器中的测试结果

问题描述

如何使用 API 在 VSTS/Microsoft 测试管理器中更新测试结果。如何使用 Selenium/Java 在 VSTS/Microsoft 测试管理器中更新测试结果。

标签: seleniumselenium-webdriverazure-devopsmicrosoft-test-manager

解决方案


通过 API 更新测试结果的程序:

  1. 首先使用以下 API 获取测试用例的 testPoints:为此,您需要计划 ID、套件 ID 和测试用例 ID。在 web 视图中打开套件,在 URL 中可以找到计划 ID 和套件 ID,测试用例 ID 是测试用例的 ID。

    得到https://{instance}/DefaultCollection/{project}/_apis/test/plans/{plan}/suites/{suite}/points?api-version={version}&testCaseId={string}

发送请求并记下 testPoints(作为响应)。

有关详细信息,请参阅:https ://docs.microsoft.com/en-us/vsts/integrate/previous-apis/test/points?view=vsts#get-a-test-point

  1. 然后为此创建一个测试运行。要创建测试运行,您需要计划 id、testPoints 和运行名称。您已经有了计划 ID,您从之前的请求中获得了 testPoints,运行名称可以是任何名称。样品要求:

邮政https://{instance}/DefaultCollection/{project}/_apis/test/runs?api-version={version}

样品主体

{
  "name": "Sprint 10 Test Run",
  "plan": {
    "id": 1234
  },
  "pointIds": [
    10
  ]
}

发送请求并记下运行 ID(响应)。

有关详细信息,请参阅:https ://docs.microsoft.com/en-us/vsts/integrate/previous-apis/test/runs?view=vsts#create-new-test-run

  1. 添加测试结果。为此,您需要测试运行 ID(您从之前的请求中获得)、测试用例 ID 和测试点(您从第一个请求中获得)。

邮政https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/results?api-version={version}

样品主体

 [
      {
        "state": "Completed",
        "testPoint": {
          "id": 10
        },
        "outcome": "Passed",
        "testCase": {
          "id": 4567
        }
      }
    ]

发送请求并记录结果 ID(来自响应)。

有关详细信息,请参阅:https ://docs.microsoft.com/en-us/vsts/integrate/previous-apis/test/results?view=vsts#add-test-results-to-a-test-run

  1. 更新测试运行为此,您需要来自先前请求的结果 id(添加结果)

修补

https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}?api-version={version}

样品主体

[
  {
    "id": 100000,
    "state": "Completed"
  }
]

有关详细信息,请参阅:https ://docs.microsoft.com/en-us/vsts/integrate/previous-apis/test/runs?view=vsts#update-test-run

现在检查 VSTS/Test Manager 以获取结果更新。此外,您还可以更新特定配置的结果,只需在添加测试结果的正文中添加配置即可。有关配置详细信息,请参阅:https ://docs.microsoft.com/en-us/vsts/integrate/previous-apis/test/configurations?view=vsts#get-a-list-of-test-configurations

现在要使用 Java 更新结果,请使用 RestAssured 发送 get、post、patch 请求并从响应中检索特定数据。有关放心的详细信息,请参阅:https ://github.com/rest-assured/rest-assured/wiki/Usage

对于发送帖子和补丁请求,您可能需要创建 json 对象/主体,为此使用 minidev json 库。如何创建 json 对象/数组:如何使用字符串创建 JSON 对象?


推荐阅读