How to update test execution status and evidence in Azure DevOps using REST API

Yosuva ArulanthuUncategorizedLeave a Comment

You will have to use the following API call:

  1. Find the test points
curl --location --request POST 'https://dev.azure.com/yosuva/Test/_apis/test/points?api-version=7.1-preview.2' \
--header 'Authorization: Basic azure_personal_access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
  "PointsFilter": {
    "TestcaseIds": [
      2,
      6,
      7
    ]
  }
}'

Response

{
    "points": [
        {
            "id": 1,
            "url": "https://dev.azure.com/yosuva/Test/_apis/test/Plans/3/Suites/5/Points/1",
            "assignedTo": {
                "displayName": "Yosuva Arulanthu <Windows Live ID\\>",
                "id": "057b2afa-2c1e-63a2-9402-20652bc0c155"
            },
            "automated": false,
            "configuration": {
                "id": "2",
                "name": "Windows 10"
            },
            "lastTestRun": {
                "id": "0"
            },
            "lastResult": {
                "id": "0"
            },
            "outcome": "Unspecified",
            "state": "Ready",
            "lastResultState": "Unspecified",
            "suite": {
                "id": "5"
            },
            "testCase": {
                "id": "2"
            },
            "testPlan": {
                "id": "3"
            },
            "workItemProperties": [
                {
                    "workItem": {
                        "key": "Microsoft.VSTS.TCM.AutomationStatus",
                        "value": "Not Automated"
                    }
                }
            ]
        },
        {
            "id": 2,
            "url": "https://dev.azure.com/yosuva/Test/_apis/test/Plans/3/Suites/5/Points/2",
            "assignedTo": {
                "displayName": "Yosuva Arulanthu <Windows Live ID\\ayosuva@gmail.com>",
                "id": "057b2afa-2c1e-63a2-9402-20652bc0c155"
            },
            "automated": false,
            "configuration": {
                "id": "2",
                "name": "Windows 10"
            },
            "lastTestRun": {
                "id": "0"
            },
            "lastResult": {
                "id": "0"
            },
            "outcome": "Unspecified",
            "state": "Ready",
            "lastResultState": "Unspecified",
            "suite": {
                "id": "5"
            },
            "testCase": {
                "id": "6"
            },
            "testPlan": {
                "id": "3"
            },
            "workItemProperties": [
                {
                    "workItem": {
                        "key": "Microsoft.VSTS.TCM.AutomationStatus",
                        "value": "Not Automated"
                    }
                }
            ]
        },
        {
            "id": 3,
            "url": "https://dev.azure.com/yosuva/Test/_apis/test/Plans/3/Suites/5/Points/3",
            "assignedTo": {
                "displayName": "Yosuva Arulanthu <Windows Live ID\\ayosuva@gmail.com>",
                "id": "057b2afa-2c1e-63a2-9402-20652bc0c155"
            },
            "automated": false,
            "configuration": {
                "id": "2",
                "name": "Windows 10"
            },
            "lastTestRun": {
                "id": "0"
            },
            "lastResult": {
                "id": "0"
            },
            "outcome": "Unspecified",
            "state": "Ready",
            "lastResultState": "Unspecified",
            "suite": {
                "id": "5"
            },
            "testCase": {
                "id": "7"
            },
            "testPlan": {
                "id": "3"
            },
            "workItemProperties": [
                {
                    "workItem": {
                        "key": "Microsoft.VSTS.TCM.AutomationStatus",
                        "value": "Not Automated"
                    }
                }
            ]
        }
    ],
    "pointsFilter": {
        "testcaseIds": [
            2,
            6,
            7
        ]
    }
}

2. Create Test Run using points

curl --location --request POST 'https://dev.azure.com//yosuva/Test//_apis/test/runs?api-version=7.1-preview.3' \
--header 'Authorization: Basic azure_personal_access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
  "name": "Run for Release 1",
  "plan": {
    "id": "3"
  },
  "pointIds": [
    1,
    2,
    3
  ]
}'

Response

{
    "id": 4,
    "name": "Run for Release 1",
    "url": "https://dev.azure.com/yosuva/Test/_apis/test/Runs/4",
    "isAutomated": false,
    "owner": {
        "displayName": null,
        "id": "00000000-0000-0000-0000-000000000000"
    },
    "project": {
        "id": "30f5518c-1199-439f-aaf4-e1f93fdeb576",
        "name": "Test"
    },
    "state": "Unspecified",
    "plan": {
        "id": "3"
    },
    "totalTests": 0,
    "incompleteTests": 0,
    "notApplicableTests": 0,
    "passedTests": 0,
    "unanalyzedTests": 0,
    "revision": 2,
    "webAccessUrl": "https://dev.azure.com/yosuva/Test/_TestManagement/Runs?runId=4&_a=runCharts"
}

3. Update the test status using Run id

curl --location --request PATCH 'https://dev.azure.com/yosuva/Test/_apis/test/Runs/4/results?api-version=7.1-preview.6' \
--header 'Authorization: Basic azure_personal_access_token' \
--header 'Content-Type: application/json' \
--data-raw '[
    {
        "id":100000,
        "state": "Completed",
        "outcome": "Passed"
    },
    {
        "id":100001,
        "state": "Completed",
        "outcome": "Passed"
    },
    {
        "id":100002,
        "state": "Completed",
        "outcome": "Passed"
    }
]'

Response

{
    "count": 3,
    "value": [
        {
            "id": 100000,
            "project": {},
            "outcome": "Passed",
            "lastUpdatedDate": "2022-11-18T16:34:32.07Z",
            "priority": 0,
            "url": "",
            "lastUpdatedBy": {
                "displayName": null,
                "id": null
            }
        },
        {
            "id": 100001,
            "project": {},
            "outcome": "Passed",
            "lastUpdatedDate": "2022-11-18T16:34:32.07Z",
            "priority": 0,
            "url": "",
            "lastUpdatedBy": {
                "displayName": null,
                "id": null
            }
        },
        {
            "id": 100002,
            "project": {},
            "outcome": "Passed",
            "lastUpdatedDate": "2022-11-18T16:34:32.07Z",
            "priority": 0,
            "url": "",
            "lastUpdatedBy": {
                "displayName": null,
                "id": null
            }
        }
    ]
}

4. Attach evidence for the specific test

curl --location --request POST 'https://dev.azure.com/yosuva/Test/_apis/test/Runs/4/Results/100000/attachments?api-version=7.1-preview.1' \
--header 'Authorization: Basic azure_personal_access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
  "stream": "VXNlciB0ZXh0IGNvbnRlbnQgdG8gdXBsb2FkLg==",
  "fileName": "textAsFileAttachment.txt",
  "comment": "Test attachment upload",
  "attachmentType": "GeneralAttachment"
}
'

Response

{
    "id": 2,
    "url": "https://dev.azure.com/yosuva/Test/_apis/test/Runs/4/Results/100000/Attachments/2"
}

5. Attachment for the test run

curl --location --request POST 'https://dev.azure.com/yosuva/Test/_apis/test/Runs/4/attachments?api-version=7.1-preview.1' \
--header 'Authorization: Basic azure_personal_access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
  "stream": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAIAAABvFaqvAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABlSURBVDhP7cxBCsAgDERR739pG/CnGJI0FopQ8O2cjNP6R85QbeNQU7wT1dkijaQ3vkZoWElaoTeJojW01cYh0jwfgiFBV/lEjOZtacijN/nLkOBHhIaVDgn+Wdycp6FXzlCl9wt0Y0cAzHo/zgAAAABJRU5ErkJggg==",
  "fileName": "imageAsFileAttachment.png",
  "comment": "Test attachment upload",
  "attachmentType": "GeneralAttachment"
}
'

Response

{
    "id": 4,
    "url": "https://dev.azure.com/yosuva/Test/_apis/test/Runs/4/Attachments/4"
}

Leave a Reply

Your email address will not be published.