TFS API: How to get latest test result for a test case
odeBlock">
Uri tfsUri =
new
Uri(
"http://servername:8080/tfs/collectionname"
);
teamProjectCollection =
new
TfsTeamProjectCollection(tfsUri);
iTestManagementService = teamProjectCollection.GetService<ITestManagementService>();
tfsConnectedTeamProject = iTestManagementService.GetTeamProject(
"Team Project Name"
);
2. Once connected to TFS server, call APIs to get test results for any particular test case. Below line of code will get all results associated with passed test case Id and this returned list is not sorted
var
testResults = tfsConnectedTeamProject.TestResults.ByTestId(52737);
3. We can sort this using below code using LastUpdated property of ITestCaseResult and it will return you sorted list of test result.
var resSort = from res
in
testResults
orderby res.LastUpdated descending
select res;
4. Now if you need only latest test result from result collection then below is code. Use above sorted list and retrieve top most record.
var latestTestResult = resSort.First<ITestCaseResult>();
Hope this help you all.
Thanks,
Vivek