我们使用 Azure DevOps 测试计划模块进行手动测试。我们有一个测试计划,在该计划下,我们有测试套件,在该计划下,我们有分配给不同测试人员的测试用例。测试人员使用 ADO 将测试用例结果标记为通过或失败。
我们想要下载测试用例结果,但我没有看到该选项。我们在“测试计划”下有一个“测试运行”选项卡,它显示所有运行结果,但不提供下载选项。
最佳答案
恐怕没有现成的方法可以直接将测试运行的测试结果导出到excel。
为了满足您的要求,您可以使用 Rest API 列出所有所需的测试运行和测试结果。然后您可以将它们导出到 Excel。
您可以使用以下两个 Rest API:
获取测试运行: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
获取测试结果: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
这是 PowerShell 示例:
$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
}
}
您可以根据需要自定义输出Excel列。
结果:
关于azure - 从 Azure DevOps 下载测试运行结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74667369/