0
votes

I am trying to create a static Test Suite using REST API but i am getting an error in my response.

i am trying to follow the 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

My Request Body

$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 

Error :

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
1
You're passing an array. According to the documentation, it shouldn't be an array.Daniel Mann
I tried removing [] tags in the body , still the same error . {"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: testSuite","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}sriram

1 Answers

0
votes

It looks like your request body is incorrect. According to the document there is no area or iteration properties in the request body.

enter image description here

See below example request body to create a static Test Suite.

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

If you want to create a Test Suite based on a query, you can specify the queryString property. See below example.

$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''"
}

See the examples in the document for more information.