I am afraid that there is no out-of-box method can directly export the test results of test runs to excel.
To meet your requirement, you can use Rest API to list all required test runs and test results. Then you can export them to Excel.
You can use the following two Rest APIs:
Get Test Runs: Runs - Query
GET https://dev.azure.com/{organization}/{project}/_apis/test/runs?minLastUpdatedDate={minLastUpdatedDate}&maxLastUpdatedDate={maxLastUpdatedDate}&state={state}&planIds={planIds}&isAutomated={isAutomated}&publishContext={publishContext}&buildIds={buildIds}&buildDefIds={buildDefIds}&branchName={branchName}&releaseIds={releaseIds}&releaseDefIds={releaseDefIds}&releaseEnvIds={releaseEnvIds}&releaseEnvDefIds={releaseEnvDefIds}&runTitle={runTitle}&$top={$top}&continuationToken={continuationToken}&api-version=7.0
Get Test Results: Results - List
GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/results?detailsToInclude={detailsToInclude}&$skip={$skip}&$top={$top}&outcomes={outcomes}&api-version=7.0
Here is PowerShell sample:
$token = "PAT"
$url=" https://dev.azure.com/orgname/projectname/_apis/test/runs?api-version=7.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
echo $response
ForEach( $testrunid in $response.value.id )
{
echo $testrunid
$url1 ="https://dev.azure.com/orgname/projectname/_apis/test/Runs/$($testrunid)/results?api-version=7.0"
$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
ForEach( $testresult in $response1.value)
{
$outcome = $testresult.outcome
$startedDate = $testresult.startedDate
$testCase =$testresult.testCase.name
$completedDate = $testresult.completedDate
$testCaseTitle = $testresult.testCaseTitle
echo $outcome
echo $startedDate
$Output = New-Object -TypeName PSObject -Property @{
outcome = $outcome
runid =$testrunid
startedDate = $startedDate
completedDate= $completedDate
testCase = $testCase
testCaseTitle = $testCaseTitle
} | Select-Object runid, outcome,startedDate,testCase,testCaseTitle,completedDate
$Output | Export-Csv C:\testresult.csv -Append
}
}
You can customize the output excel column according to your requirements.
Result:
