如何在 C# 中通过 Release ID 从 TFS 获取测试结果
How to get test results from TFS by Release ID in C#
我无法找到在 C# 中获取给定版本的测试结果的方法。
我之前做的是,通过build ID获取测试结果。
这是示例代码
int buildId = 123;
const string TFS_url = "<TFS_URL>";
string projectname = "<Teamname>";
TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(TFS_url));
// Get build information
BuildHttpClient bhc = ttpc.GetClient<BuildHttpClient>();
// Get testrun for the build
TestManagementHttpClient ithc = ttpc.GetClient<TestManagementHttpClient>();
QueryModel qm = new QueryModel("Select * From TestRun Where BuildNumber Contains '" + buildId + "'");
List<TestRun> testruns = ithc.GetTestRunsByQueryAsync(qm, projectname).Result;
List<List<TestCaseResult>> allTestresults = new List<List<TestCaseResult>>();
foreach (TestRun testrun in testruns)
{
List<TestCaseResult> testresults = ithc.GetTestResultsAsync(projectname, testrun.Id).Result;
allTestresults.Add(testresults);
}
我更愿意在 C# 中使用给定的 类 而不必通过 API.
build/release的测试结果存储在test 运行s中,所以你只需要获取测试运行 的 build/release 然后从测试 运行.
中检索测试结果
您可以从特定版本的测试日志中获取测试 运行 id。
因此,最简单的方法是从日志中获取带有 REST API 的特定测试 运行 id。
GET https://{instance}/{project}/_apis/release/releases/{releaseId}/environments/{environmentId}/deployPhases/{releaseDeployPhaseId}/tasks/{taskId}/logs?api-version={version}
详情见Get Task Log v5。
然后只需通过测试运行 ID 即可获取测试结果详情。与您用于构建的共享代码示例类似。
我无法找到在 C# 中获取给定版本的测试结果的方法。
我之前做的是,通过build ID获取测试结果。
这是示例代码
int buildId = 123;
const string TFS_url = "<TFS_URL>";
string projectname = "<Teamname>";
TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(TFS_url));
// Get build information
BuildHttpClient bhc = ttpc.GetClient<BuildHttpClient>();
// Get testrun for the build
TestManagementHttpClient ithc = ttpc.GetClient<TestManagementHttpClient>();
QueryModel qm = new QueryModel("Select * From TestRun Where BuildNumber Contains '" + buildId + "'");
List<TestRun> testruns = ithc.GetTestRunsByQueryAsync(qm, projectname).Result;
List<List<TestCaseResult>> allTestresults = new List<List<TestCaseResult>>();
foreach (TestRun testrun in testruns)
{
List<TestCaseResult> testresults = ithc.GetTestResultsAsync(projectname, testrun.Id).Result;
allTestresults.Add(testresults);
}
我更愿意在 C# 中使用给定的 类 而不必通过 API.
build/release的测试结果存储在test 运行s中,所以你只需要获取测试运行 的 build/release 然后从测试 运行.
中检索测试结果您可以从特定版本的测试日志中获取测试 运行 id。
因此,最简单的方法是从日志中获取带有 REST API 的特定测试 运行 id。
GET https://{instance}/{project}/_apis/release/releases/{releaseId}/environments/{environmentId}/deployPhases/{releaseDeployPhaseId}/tasks/{taskId}/logs?api-version={version}
详情见Get Task Log v5。
然后只需通过测试运行 ID 即可获取测试结果详情。与您用于构建的共享代码示例类似。