I am using TFS 2015 to build, deploy and Run my selenium UI tests. Its working fine for me. I also have different build definition for different customers(tests run here are same but they run against different dbs).
My Tests Run every night and in morning I have to individually go to every build definition to see the result(I get a mail with the numbers of test fail and pass). but to see which test are failing and other details like why it is failing i need to go to the TFS build def on the server every time.
I intend to make a simple app which will fetch me that data display it at one place like a simple MVC web app(internal purpose). so far I am only able to get the simple data of the build like name and result by using
using Microsoft.TeamFoundation.Build.WebApi;
but I am not able to get the test run details and event the individual test details can anyone suggest me which API can I use to achieve this and display the data in simpler form.
I got to this link but I am not sure how can I consume this in my app. https://www.visualstudio.com/en-us/docs/integrate/api/test/results
Thanks,
Amey
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: