如何使用 APIs/endpoint 在 VSTS/Microsoft 测试管理器中更新测试结果

How to update test results in VSTS/Microsoft Test Manager using APIs/endpoint

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

在 VSTS/Microsoft 测试管理器中更新测试结果

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

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

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

发送请求并记下测试点(作为响应)。

详情参考:https://docs.microsoft.com/en-us/vsts/integrate/previous-apis/test/points?view=vsts#get-a-test-point

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

POST 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 和测试点(您从第一个请求中获得)。

POST 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 经理以获取结果更新。 此外,您还可以更新特定配置的结果,只需在添加测试结果的主体中添加配置即可。 配置详情参考:https://docs.microsoft.com/en-us/vsts/integrate/previous-apis/test/configurations?view=vsts#get-a-list-of-test-configurations

现在使用 Java 更新结果,使用 RestAssured 发送 get、post、补丁请求并从响应中检索特定数据。 放心详情参考:https://github.com/rest-assured/rest-assured/wiki/Usage

为了发送 post 和补丁请求,您可能需要创建 json objects/bodies,为此使用 minidev json 库。 如何创建jsonobject/array:How to create JSON Object using String?