首页 > 解决方案 > 使用 Azure Devops REST API 创建静态测试套件时出错

问题描述

我正在尝试使用 REST API 创建一个静态测试套件,但我的响应中出现错误。

我正在尝试遵循https://docs.microsoft.com/en-us/rest/api/azure/devops/test/test%20%20suites/create?view=azure-devops-rest-5.0&viewFallbackFrom=azure -devops-rest-6.0

我的请求正文

$body= @"
[ {
  "suiteType": "StaticTestSuite",
  "name": "NewTestSuite",
  "area": {
    "name": "<TeamName>"
  },
  "iteration": "<Iteration>"   
}
]"@

$BuildReqBodyJson = $body | ConvertTo-Json

$response = Invoke-RestMethod -Uri $Uri  -Method POST -Headers $header -ContentType "application/json"  -Body $BuildReqBodyJson 

错误 :

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: 
testSuite","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}
At

+ $response = Invoke-RestMethod -Uri $Uri  -Method POST -Headers $heade ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

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

解决方案


看起来您的请求正文不正确。根据文档,请求正文中没有areaiteration属性。

在此处输入图像描述

请参阅下面的示例请求正文以创建静态测试套件。

$body='
{
  "suiteType": "StaticTestSuite",
  "name": "NewTestSuite"
}
'

如果要基于查询创建测试套件,可以指定queryString属性。请参见下面的示例。

$body='
{
  "suiteType": "DynamicTestSuite",
  "name": "allTestSuite",
  "queryString": "SELECT [System.Id],[System.WorkItemType] FROM WorkItems WHERE [System.WorkItemType] IN GROUP ''Microsoft.TestCaseCategory''  AND [System.AreaPath]=''myareapath'' AND [System.IterationPath] = ''myiterationpath''"
}

有关详细信息,请参阅文档中的示例


推荐阅读