You can get the test results for a specific project with the REST API (The link you mentioned above)
For example, below PowerShell script sample can get all the failed test results from a specific project and alternatively export to .csv file, then open it in Excel to filter later:
Param(
[string]$collectionurl = "http://server:8080/tfs/Collection",
[string]$project = "ProjectName",
[string]$user = "username",
[string]$token = "password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
#Get test runs
$testrunsUrl = "$collectionurl/$project/_apis/test/runs?api-version=1.0"
$testruns = (Invoke-RestMethod -Uri $testrunsUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}).value
#Get unit tests from each test run
$UnitTestResults = @()
foreach ($testrun in $testruns)
{
$testrunID = $testrun.id
#Get test results for specific test run
$baseUrl = "$collectionurl/$project/_apis/test/runs/$testrunID/results?api-version=3.0-preview"
$response = Invoke-RestMethod -Uri $baseUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$unittests = $response.value | where({$_.outcome -eq 'Failed'})
$customObject = new-object PSObject -property @{
"ComputerName" = @($unittests.computerName -join ',')|Select-Object
"BuildId" = @($unittests.build.id -join ',')|Select-Object
"BuildName" = @($unittests.build.name -join ',')|Select-Object
"BuildUrl" = @($unittests.build.url -join ',')|Select-Object
"TestRunID" = $testrunID
"ProjectName" = @($unittests.project.name -join ',')|Select-Object
"TestRunName" = @($unittests.testRun.name -join ',')|Select-Object
"TestRunURL" = @($unittests.testRun.url -join ',')|Select-Object
"UnitTestname" = @($unittests.automatedTestName -join ',')|Select-Object
"outcome" = @($unittests.outcome -join ',')|Select-Object
"errorMessage" = @($unittests.errorMessage -join ',')|Select-Object
"TestResultsUrl" = @($unittests.url -join ',')|Select-Object
"completedDate" = @($unittests.completedDate -join ',')|Select-Object
}
$UnitTestResults += $customObject
}
$UnitTestResults | Select `
ProjectName,
ComputerName,
BuildId,
BuildName,
BuildUrl,
TestRunID,
TestRunName,
TestRunURL,
UnitTestname,
outcome,
errorMessage,
TestResultsUrl,
completedDate | where({$_.outcome -like '*Failed*'}) #|export-csv -Path C:\LC\UnitTest.csv -NoTypeInformation
You can also use the TFS API to achieve that.
The test result of the build is stored in test runs, so you need to get the test run of the build first and then retrieve the test result from the test run.
You can reference below threads:
