Search code examples
c#azure-devopsautomated-testsazure-pipelinestfsbuild

Getting Build Test Results from Azure DevOps in C# app


I am making a program in ASP .NET Core and I am trying to get the Test Runs for specific build in specific Build Definition. So far I have created some some methods which can get the build definition and all night builds for that specific build. Now I would like to get all test results from the mentioned night build

enter image description here

The Idea is to get the list of all tests and do some statistics with them. I am using the following libraries

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

I am not using any RestAPI queries for now. Only these pre-designed methods from mentioned libs (I know that they are using Rest service in the background) and I hope that I can somehow manage to do it with these methods. Is there a way to do so?

Thanks for possible solutions


Solution

  • It looks like the 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, which returns the full info about the test result.

    If there are lots of results, you might want to obtain them page by page. In this case, use the GetTestResultsByBuildAsync2 method (note 2 at the end of the method name). It returns the paged list collection, which contains the ContinuationToken property.

    When you request the first Top results, that property will hold the continuation token, in case there are more results to return. You should supply that token to the subsequent call. Repeat that until the continuation token is null in the resulting collection.