Tike Myson
Tike Myson

Reputation: 27

Get a detailed Testreport export on Azure Devops

I am searching for a way to get a detailed test report export on Azure Devops. My goal is to not only display if the test is passed or failed, but to also display the detailed teststeps and the comments that I added during the testing.

Upvotes: 0

Views: 607

Answers (1)

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35099

I am afraid that there is no out-of-the-box method to meet your requirements.

Currently, the existing feature of azure devops only support exporting the latest results of the test step. But it will not contain the test comment and outcome for each test step. enter image description here

So you can try to use Rest Api to get data and generate reports.

Here is an example: Runs - List and Results - Get

$token = "PAT"

$url="https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/test/runs?api-version=6.0"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json

ForEach( $testrunid in $response.value.id)
{

   $url1 = "https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/test/Runs/$($testrunid)/results/100000?detailsToInclude=5&api-version=6.0" 
   $response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json

   ForEach( $teststep in $response1.iterationDetails.actionResults)
   {
         $testcaseid = $response1.testcase.id

         $testcasename = [String]$response1.testcase.name

         $testplanid = $response1.testPlan.id

         $testsuiteid =  $response1.testSuite.id

         $testsuitename =  $response1.testSuite.name

         $teststepid = $teststep.stepIdentifier

         $teststepoutcome = $teststep.outcome

         $teststepcomment = $teststep.errorMessage

         

         $Output = New-Object -TypeName PSObject -Property @{
             testcaseid = $testcaseid
             testcasename = $testcasename
             testplanid = $testplanid
             testsuiteid = $testsuiteid
             testsuitename = $testsuitename
             teststepid = $teststepid
             teststepoutcome = $teststepoutcome
             teststepcomment = $teststepcomment
          } | Select-Object testcaseid, testcasename,testplanid,testsuiteid,testsuitename,teststepid,teststepoutcome,teststepcomment
          $Output | Export-Csv D:\TestReportsample.csv -Append
   
   }

}

Result:

enter image description here

If you want to get more detailed functions, you need to add more APIs to implement this function. This will greatly increase the amount of code.

So I suggest that you could create a suggestion tikcet in Our UserVoice Site to report this feature.

Here is an existing suggestion ticket, you can also refer to it: Detailed Test Summary Reports

Upvotes: 1

Related Questions