How to create test case in azure devops using rest api in python

2.9k Views Asked by At

Can anyone please share the details how to create a test case in azure devops using rest api, preferably in python code. I couldn't find a direct API in azure devops but they shared an API for work item. But I don't have an idea how the body should be while creating a test case. Please suggest.

https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/create?view=azure-devops-rest-6.1

1

There are 1 best solutions below

1
On

How to create test case in azure devops using rest api in python

The test case is also a work item. That is the reason why they shared an API for work item for you.

When you create a workitem with TestCase type:

enter image description here

Then we could find it display on the test case tab:

enter image description here

So, we could use the REST API Create a work item to create a workitem with Testcase type to create the test case:

PATCH https://{instance}/DefaultCollection/{project}/_apis/wit/workitems/${workItemTypeName}?api-version={version}

On the other hand, we could check the REST API about the Test cases, there are Get a test case, Delete a test case but no create the test case API directly.

To create a workitem in python, you could refer this official Azure DevOps Python API doc.

It contains Python APIs for interacting with and managing Azure DevOps. These APIs power the Azure DevOps Extension for Azure CLI. To learn more about the Azure DevOps Extension for Azure CLI, visit the Microsoft/azure-devops-cli-extension repo.

Here is some example code for creating work item in python.

You could check this thread for some more details.