首页 > 解决方案 > VSTS - 测试 -> 运行 -> 查询端点未根据参数进行过滤

问题描述

我正在尝试使用 Test -> Runs -> Query 端点来返回特定版本的测试运行列表,详见此处

不幸的是,无论我作为查询参数输入什么($top似乎过滤的除外),我似乎都得到了针对项目返回的每个测试运行。

例如,我知道针对特定版本有 14 次测试运行。

在此处输入图像描述

我可以通过以下查询获取我的发布 ID...

https://smartassessor.vsrm.visualstudio.com/Smart End Point Assessment/_apis/release/releases?searchText=Release-103

如果我然后尝试在这样的测试运行查询中使用该 ID...

https://smartassessor.visualstudio.com/Smart End Point Assessment/_apis/test/runs?releaseIds=1678&api-version=5.0-preview.2

我得到 529 个结果,看起来大多数测试都是针对该项目运行的。

过滤器是否针对此端点工作?如果是这样,我应该如何调整我的请求以使用该releaseIds参数。

谢谢

标签: azure-devopsazure-devops-rest-api

解决方案


我可以重现这个问题。似乎 API 暂时不可用。

此处提交了一个问题以跟踪此问题。您还可以跟踪它的更新。

作为一种解决方法,您可以使用下面的 PowerShell 脚本按版本 ID 过滤测试运行:(或者,您可以将结果导出到*.CSV文件)

Param(
   [string]$collectionurl = "https://{account}.visualstudio.com", 
   [string]$project = "ProjectName",
   [string]$releaseid = "1",
   [string]$user = "username",
   [string]$token = "password"
)

#Set the path and name for the output csv file
$path = "D:\temp"
$filename = "ReleaseTestRun" + "-" + $releaseid


# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$baseUrl = "$collectionurl/$project/_apis/test/runs"
$response = Invoke-RestMethod -Uri $baseUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$testruns = $response.value 
Write-Host $results

$Releaseruns = @()

foreach ($testrun in $testruns)
{
$testrunID = $testrun.id
$runbaseUrl = "$collectionurl/$project/_apis/test/runs/$testrunID"
$runresponse = Invoke-RestMethod -Uri $runbaseUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} | Where {$_.release.id -eq $releaseid} #| Filter the test run by Release ID

$customObject = new-object PSObject -property @{
          "id" = $runresponse.id
          "name" = $runresponse.name
          "url" = $runresponse.url
          "isAutomated" = $runresponse.isAutomated
          "state" = $runresponse.state
          "totalTests" = $runresponse.totalTests
          "incompleteTests" = $runresponse.incompleteTests
          "notApplicableTests" = $runresponse.notApplicableTests
          "passedTests" = $runresponse.passedTests
          "unanalyzedTests" = $runresponse.unanalyzedTests
          "revision" = $runresponse.revision
          "webAccessUrl" = $runresponse.webAccessUrl
        } 

    $Releaseruns += $customObject
}

$Releaseruns | Select `
                id,
                name,
                url,
                isAutomated,
                state,
                totalTests,
                incompleteTests,
                notApplicableTests,
                passedTests,
                unanalyzedTests,
                revision,
                webAccessUrl | where {$_.id -ne $Null} #|export-csv -Path $path\$filename.csv -NoTypeInformation # Filter non-empty values and export to csv file.

在此处输入图像描述


推荐阅读