【问题标题】:TFS Rest API: parameter outcomes to filter test results is not workingTFS Rest API:过滤测试结果的参数结果不起作用
【发布时间】:2018-10-05 20:36:23
【问题描述】:

我们一直在修补 TFS REST API。我们的目标是从特定的测试运行中获取测试结果,并且只返回失败的测试。

documentation 中声明使用参数“outcomes”,但是当我们添加此参数时,GET 操作仍然返回所有测试结果,包括传递的结果。

我们使用的是 2.0 版,但我们找不到此版本的特定文档。

这是我们调用的一个例子。

https://<server>/tfs/<collection>/<project>/_apis/test/Runs/<run id>/results?api-version=2.0&outcomes=Failed

非常感谢有关此过滤如何工作的任何帮助(或者如果这不适用于 2.0 版,则提供明确的答案)。

【问题讨论】:

  • 很可能outcomes 参数随API 的较新版本一起到达。只要你在这个问题上添加了tfs2017标签,我想你已经安装了这个版本的TFS,它带有API v3.0:docs.microsoft.com/en-us/vsts/integrate/concepts/…。您可以使用api-version=3.0 尝试相同的呼叫。如果还是不行,那肯定是从某个较新的版本开始支持的...
  • 感谢您的帮助@YanSklyarenko,确实,我们使用带有最新更新的 TFS 2017。我尝试了 3.0,不幸的是它没有工作。
  • 它仅适用于 4.1 及更高版本。

标签: rest tfs


【解决方案1】:

在我这边测试,似乎它不适用于以前的 API 版本(在 TFS 2017 和 2018 上测试,两者都不起作用)。

api-version=5.0-preview.5 中提到的documentation,可能会在以后的版本中提供。

但是,您可以使用带有 REST API 的 PowerShell 按结果过滤测试结果,请参见以下示例:

Param(
   [string]$collectionurl = "http://server:8080/tfs/DefaultCollection", 
   [string]$project = "ProjectName",
   [string]$testrunID = 223,
   [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)))

$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)}
$results = $response.value | Where {$_.outcome -eq "Failed"} #| Filter the test results by outcomes


$TestResults = @()

foreach ($result in $results)
{

$customObject = new-object PSObject -property @{
          "TestResultID" = $result.id
          "projectName" = $result.project.name
          "testCaseName" = $result.testCase.name
          "startedDate" = $result.startedDate
          "completedDate" = $result.completedDate
          "outcome" = $result.outcome
          "state" = $result.state
          "runBy" = $result.runBy.uniqueName
          "errorMessage" = $result.errorMessage
        } 

    $TestResults += $customObject
}

$TestResults | Select `
                TestResultID,
                projectName, 
                testCaseName,
                startedDate,
                completedDate,
                outcome,
                state,
                runBy,
                errorMessage #|export-csv -Path D:\temp\TestResult.csv -NoTypeInformation # Export to .csv file

【讨论】:

  • @WietzeVeldf 您是否通过上述答案解决了问题?有更新吗?
  • 感谢过滤器的替代解决方案 - 很抱歉迟到的答案 -。由于其他优先事项,我们推迟了该项目,但会将其留到未来。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-23
  • 2018-12-10
  • 2021-02-10
  • 2015-12-25
  • 2017-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多