Azure DevOps REST API: Match Manual Test Case Steps to Test Run Results – A Step-by-Step Guide
Image by Edira - hkhazo.biz.id

Azure DevOps REST API: Match Manual Test Case Steps to Test Run Results – A Step-by-Step Guide

Posted on

Are you tired of manually matching test case steps to test run results in Azure DevOps? Do you wish there was a way to automate this process and save valuable time? Look no further! In this article, we’ll explore how to use the Azure DevOps REST API to match manual test case steps to test run results with ease.

Why Automate Test Case Matching?

Manual test case matching can be a tedious and time-consuming task, especially when dealing with large test suites and numerous test runs. By automating this process, you can:

  • Reduce manual effort and increase productivity
  • Eliminate errors and inconsistencies
  • Improve testing efficiency and reduce testing time
  • Enhance collaboration and visibility across teams

Prerequisites

Before we dive into the tutorial, make sure you have the following:

  • Azure DevOps account with the Test Plans extension installed
  • Basic knowledge of Azure DevOps REST API and HTTP requests
  • A tool or platform for making HTTP requests (e.g., Postman, curl, or Python)

Understanding Azure DevOps REST API Endpoints

The Azure DevOps REST API provides several endpoints for interacting with test cases, test runs, and test results. We’ll focus on the following endpoints:

Endpoint Description
https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{planId}/Suites/{suiteId}/TestCases/{testCaseId} Retrieve a test case by its ID
https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/Results Retrieve test results for a test run
https://dev.azure.com/{organization}/{project}/_apis/test/TestResults/{resultId} Retrieve a test result by its ID

Matching Test Case Steps to Test Run Results

Now that we have the necessary endpoints, let’s create a script to match manual test case steps to test run results.

Step 1: Retrieve Test Case Steps

Use the first endpoint to retrieve the test case steps:

GET https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{planId}/Suites/{suiteId}/TestCases/{testCaseId}

Response:

{
    "testCase": {
        "id": 12345,
        "steps": [
            {
                "id": 1,
                "action": "Step 1: Launch the application"
            },
            {
                "id": 2,
                "action": "Step 2: Login with valid credentials"
            },
            {
                "id": 3,
                "action": "Step 3: Verify the dashboard"
            }
        ]
    }
}

Step 2: Retrieve Test Run Results

Use the second endpoint to retrieve the test run results:

GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/Results

Response:

{
    "results": [
        {
            "id": 54321,
            "testCaseId": 12345,
            "outcome": "Passed",
            "message": "Test passed"
        },
        {
            "id": 54322,
            "testCaseId": 12345,
            "outcome": "Failed",
            "message": "Test failed"
        },
        {
            "id": 54323,
            "testCaseId": 12345,
            "outcome": "Passed",
            "message": "Test passed"
        }
    ]
}

Step 3: Match Test Case Steps to Test Run Results

Loop through each test case step and match it to the corresponding test run result:

for step in testCaseSteps:
    for result in testRunResults:
        if step["id"] == result["testCaseStepId"]:
            print(f"Matched step {step['action']} to result {result['outcome']}")
            # Update the test case step with the test run result
            UPDATE https://dev.azure.com/{organization}/{project}/_apis/test/TestResults/{resultId}
            {
                "testCaseStepId": step["id"]
            }

This script will match each test case step to its corresponding test run result, updating the test case step with the outcome of the test run.

Conclusion

By using the Azure DevOps REST API, we’ve successfully automated the process of matching manual test case steps to test run results. This script can be scheduled to run periodically, ensuring that your test cases are always up-to-date and reflecting the latest test run outcomes.

Remember to adapt this script to your specific needs and requirements. You can also extend it to include additional logic, such as handling errors and exceptions, or integrating with other Azure DevOps features.

Next Steps

Take your automation to the next level by exploring other Azure DevOps REST API endpoints and integrating them with your testing workflow. Some ideas include:

  1. Automating test case creation and updating
  2. Integrating with CI/CD pipelines for automated testing
  3. Creating custom dashboards for test case and test run visualization

The possibilities are endless with the Azure DevOps REST API. Start automating your testing workflow today and unlock the full potential of Azure DevOps!

Note: This article is for educational purposes only and should not be used in production without proper testing and validation. Additionally, the Azure DevOps REST API may change over time, so be sure to check the official documentation for the most up-to-date information.

Frequently Asked Question

Get ready to ace your Azure DevOps game! Here are the top 5 questions and answers about matching manual test case steps to test run results using Azure DevOps REST API.

How do I get started with matching manual test case steps to test run results using Azure DevOps REST API?

To begin, you’ll need to authenticate with Azure DevOps using an access token or credentials. Then, use the Test Case and Test Run APIs to retrieve the test case steps and test run results. You can then match the steps to the results by using the `testCaseResult` endpoint to link the test case step ID to the test run result ID.

What Azure DevOps REST API endpoint should I use to retrieve test case steps?

You can use the `GET https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{planId}/Suites/{suiteId}/TestCases/{testCaseId}/Steps` endpoint to retrieve the test case steps. Replace the placeholders with your actual organization, project, plan ID, suite ID, and test case ID.

How do I retrieve test run results using Azure DevOps REST API?

To get the test run results, use the `GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/Results` endpoint. Replace the placeholders with your actual organization, project, and run ID. You can also use the `GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/Results/{resultCode}` endpoint to retrieve results for a specific result code.

Can I update test case steps and test run results using Azure DevOps REST API?

Yes, you can update test case steps and test run results using the Azure DevOps REST API. Use the `PATCH https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{planId}/Suites/{suiteId}/TestCases/{testCaseId}/Steps/{stepId}` endpoint to update a test case step, and the `PATCH https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/Results/{resultCode}` endpoint to update a test run result.

Are there any limitations to consider when using Azure DevOps REST API to match manual test case steps to test run results?

Yes, there are some limitations to keep in mind. For example, the API requests may be rate-limited, and you may need to handle errors and exceptions. Additionally, the API may not return all the data you need, so be prepared to make multiple requests or use other APIs to get the required data.