我如何检查我的某些工作项是否有测试用例失败
How can i check if some of my work items have a test case failing
在 azure devops 中执行我的管道时,如何检查我的某些工作项是否有测试用例失败?
How can i check if some of my work items have a test case failing
测试用例没有结果状态(例如失败通过..)。结果状态是 Test Plan
-> Execute tab
.
中的测试点
如果我们在看板中添加测试用例运行,它会自动创建测试计划、测试套件和测试运行,我们可以通过它们检查结果。
要检查 PBI 中是否有失败的测试点(您的工作项类型),我们可以使用 PowerShell Task 并输入以下脚本来列出结果。
cls
$PAT="{PAT}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
#Get serviceHost ID
$serviceHostURL = "https://vssps.dev.azure.com/{Org name}/_apis/graph/users?api-version=6.0-preview.1"
$serviceHostResult = Invoke-RestMethod -Uri $serviceHostURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
ForEach ($ID in $serviceHostResult.value){
#filter the link type and get the test case ID
if($ID.displayName -eq "Project Collection Build Service ({Org name})"){
$serviceHost = $ID.principalName
}
}
#List all test case ID
$URL="https://dev.azure.com/{Org name}/{Project name}/_apis/wit/workitems/{Work item ID}?" + "$" + "expand=1&api-version=6.1-preview.3"
$Result = Invoke-RestMethod -Uri $URL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
$test=$Result.relations.url
ForEach ($ID in $Result.relations){
#filter the link type and get the test case ID
if($ID.rel -eq "Microsoft.VSTS.Common.TestedBy-Forward"){
$TestCaseID = $ID.url.split("/",9)[-1]
#Get test run ID via test plan ID, test suit ID and test case ID
$Url = "https://dev.azure.com/{Org name}/_apis/Contribution/HierarchyQuery?api-version=5.0-preview"
$Body = @"
{
"contributionIds": [
"ms.vss-test-web.testcase-results-data-provider"
],
"dataProviderContext": {
"properties": {
"testCaseId": $TestCaseID,
"sourcePage": {
"url": "https://dev.azure.com/{Org name}/{Project name}/_testPlans/execute?planId={Test Plan ID}&suiteId={Test Suite ID}",
"routeId": "ms.vss-test-web.testplans-hub-refresh-route",
"routeValues": {
"project": "{Project name}",
"pivots": "execute",
"controller": "ContributedPage",
"action": "Execute",
"serviceHost": "$serviceHost ({Org name})"
}
}
}
}
}
"@
#Get outcome result via run ID
$Result = Invoke-RestMethod -Uri $Url -ContentType "application/json" -Body $Body -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST
$RunID = $Result.dataProviders."ms.vss-test-web.testcase-results-data-provider".results.runId[0]
$OutComeUrl="https://dev.azure.com/{Org name}/{Project name}/_apis/test/runs/$($RunID)?api-version=6.1-preview.3"
$OutComeResult = Invoke-RestMethod -Uri $OutComeUrl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
$TestCaseResult = $OutComeResult.runStatistics.outcome
Write-Host "Test case" $TestCaseID "outcome is:" $TestCaseResult
}
}
结果:
在 azure devops 中执行我的管道时,如何检查我的某些工作项是否有测试用例失败?
How can i check if some of my work items have a test case failing
测试用例没有结果状态(例如失败通过..)。结果状态是 Test Plan
-> Execute tab
.
如果我们在看板中添加测试用例运行,它会自动创建测试计划、测试套件和测试运行,我们可以通过它们检查结果。
要检查 PBI 中是否有失败的测试点(您的工作项类型),我们可以使用 PowerShell Task 并输入以下脚本来列出结果。
cls
$PAT="{PAT}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
#Get serviceHost ID
$serviceHostURL = "https://vssps.dev.azure.com/{Org name}/_apis/graph/users?api-version=6.0-preview.1"
$serviceHostResult = Invoke-RestMethod -Uri $serviceHostURL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
ForEach ($ID in $serviceHostResult.value){
#filter the link type and get the test case ID
if($ID.displayName -eq "Project Collection Build Service ({Org name})"){
$serviceHost = $ID.principalName
}
}
#List all test case ID
$URL="https://dev.azure.com/{Org name}/{Project name}/_apis/wit/workitems/{Work item ID}?" + "$" + "expand=1&api-version=6.1-preview.3"
$Result = Invoke-RestMethod -Uri $URL -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
$test=$Result.relations.url
ForEach ($ID in $Result.relations){
#filter the link type and get the test case ID
if($ID.rel -eq "Microsoft.VSTS.Common.TestedBy-Forward"){
$TestCaseID = $ID.url.split("/",9)[-1]
#Get test run ID via test plan ID, test suit ID and test case ID
$Url = "https://dev.azure.com/{Org name}/_apis/Contribution/HierarchyQuery?api-version=5.0-preview"
$Body = @"
{
"contributionIds": [
"ms.vss-test-web.testcase-results-data-provider"
],
"dataProviderContext": {
"properties": {
"testCaseId": $TestCaseID,
"sourcePage": {
"url": "https://dev.azure.com/{Org name}/{Project name}/_testPlans/execute?planId={Test Plan ID}&suiteId={Test Suite ID}",
"routeId": "ms.vss-test-web.testplans-hub-refresh-route",
"routeValues": {
"project": "{Project name}",
"pivots": "execute",
"controller": "ContributedPage",
"action": "Execute",
"serviceHost": "$serviceHost ({Org name})"
}
}
}
}
}
"@
#Get outcome result via run ID
$Result = Invoke-RestMethod -Uri $Url -ContentType "application/json" -Body $Body -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST
$RunID = $Result.dataProviders."ms.vss-test-web.testcase-results-data-provider".results.runId[0]
$OutComeUrl="https://dev.azure.com/{Org name}/{Project name}/_apis/test/runs/$($RunID)?api-version=6.1-preview.3"
$OutComeResult = Invoke-RestMethod -Uri $OutComeUrl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -Method get
$TestCaseResult = $OutComeResult.runStatistics.outcome
Write-Host "Test case" $TestCaseID "outcome is:" $TestCaseResult
}
}
结果: