为Azure DevOps管道中的每个失败的测试用例创建一个特定的工作项(错误)



我正在使用VS测试任务进行自动测试,作为我在Azure DevOps中发行管道的一部分。在构建管道中,如果整个构建失败是定义的一部分,则可以选择创建错误。在发行定义中,我看不到这一点。

,但我很好奇,如果我在一个测试套件中有10例测试用例,并且有2例测试用例失败了,并且通过了8个测试用例。因此,是否有任何方法仅作为发布管道的一部分,仅为失败的测试用例创建工作项目(错误(。

,即使使用PowerShell/REST API调用以获取失败的测试用例并为每种情况创建错误,请建议我。

  1. 步骤:读取您的构建pipeline的运行以获取运行ID -link

url:

GET http://{instance}/{collection}/{project}/_apis/test/runs?api-version=5.0
  1. 步骤:读取特定运行的结果 - 链接

url:

GET https://{instance}/{collection}/{project}/_apis/test/Runs/{runId}/results/{testCaseResultId}?api-version=5.0
  1. 步骤:分析响应

从步骤2开始,您将获得结构的JSON呼吸:

  "startedDate": "2019-07-26T04:42:59.097Z",
  "completedDate": "2019-07-26T04:42:59.107Z",
  "durationInMs": 10,
  "outcome": "Passed",
  "revision": 1,
  "state": "Completed",
  "testCase": {
    "name": "TestConstructorDescriptor"
  },
  "startedDate": "2019-07-31T09:07:51.153Z",
  "completedDate": "2019-07-31T09:07:51.153Z",
  "outcome": "Failed",
  "revision": 1,
  "state": "Completed",
  "testCase": {
    "name": "TestCreateTelegrams"
  },
  1. 步骤:使用Failed结果进行过滤测试,并将元信息存储在数组中
  2. 步骤:创建您的Workitem-链接

有效载荷:

[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "Sample task"
  }
]

url:

POST https://{instance}/{collection}/{project}/_apis/wit/workitems/${type}?api-version=5.0

将所有这些步骤包裹在脚本(PowerShell(中,并在vstest任务后添加到buildPipeline中。这些片段可能会有所帮助:

授权标题:(需要个人访问令牌(

#AUTHORIZATION HEADERS
$headers = @{
    "Authorization" = ('Basic {0}' -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)")))
    "If-Match"      = ""
}

REST API INDOKE-RESTMETHOD:(编辑-Method GET or POST(

$url = "<Enter url from steps 1, 2 or 5>"
$projs = Invoke-RestMethod -Uri $url -Method GET -ContentType "application/json" -Headers $headers -Verbose

创建有效载荷:

$json = @{ "op" = "add"; "path" = "$path"; ... } | ConvertTo-Json

获取ETAG:(PUTPOST可能需要的方法,在 Invoke-reastMethod (之前执行(

$request = Invoke-WebRequest -Uri $url -Method GET -ContentType "application/json" -Headers $headers -Verbose
$headers.'If-Match' = $request.Headers.ETag

希望这会有所帮助。

是的,您可以创建一个powershell脚本

  1. 获取项目列表。
  2. 根据您的项目获取测试运行列表。
  3. 从测试运行列表中获取最后一个运行对象。
  4. 获取最后一个运行ID&amp;名称。
  5. 从您上次运行中获得/失败的测试用例
  6. 为失败的测试用例创建错误

单击[此处] https://github.com/ppardesi/createabug供您参考,以在REST API的帮助下从PowerShell中创建一个错误。

然后使用:

编辑管道
  1. 在管道中发布测试结果任务后,在管道中创建PowerShell任务。
  2. 您可以通过文件或Inline方法配置PowerShell脚本。
  3. 设置您的任务控件选项 - 即使以前的任务失败了,除非构建被取消。
  4. 还可以使您的代理商允许脚本访问oauth token

相关内容

最新更新