在 C# 应用程序中从 Azure DevOps 获取构建测试结果

Getting Build Test Results from Azure DevOps in C# app

我正在 ASP .NET Core 中制作一个程序,我正在尝试为特定构建定义中的特定构建获取测试运行。到目前为止,我已经创建了一些方法,可以获取构建定义和特定构建的通宵构建。现在我想从提到的夜间构建中获得所有测试结果

想法是获取所有测试的列表并对它们进行一些统计。我正在使用以下库

using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.TeamFoundation.TestManagement.WebApi;

我现在没有使用任何 RestAPI 查询。只有提到的库中的这些预先设计的方法(我知道他们在后台使用 Rest 服务),我希望我能以某种方式设法用这些方法来做到这一点。有办法吗?

感谢您提供可能的解决方案

它看起来像 GetTestResultsByBuildAsync method of the TestManagementHttpClient class is what you're looking for. It returns a list of ShallowTestCaseResult instances. It contains very basic info about each test run, but you can use the Id of each entity in that list and feed it to the GetTestResultByIdAsync method,其中 return 是有关测试结果的完整信息。

如果有很多结果,您可能希望逐页获取它们。在这种情况下,使用the GetTestResultsByBuildAsync2 method(注意方法名称末尾的2)。它 return 是分页列表集合,其中包含 ContinuationToken 属性.

当您请求第一个 Top 个结果时,属性 将保留延续令牌,以防 return 有更多结果。您应该将该令牌提供给后续调用。重复该操作,直到生成的集合中的延续标记为空。