Rediger

Del via


Associate automated tests with test cases

Azure DevOps Services | Azure DevOps Server | Azure DevOps Server 2022

Associate automated tests with test cases to enable traceability between your test code and requirements. When you link an automated test method to a test case work item, you can:

  • Run automated tests from test plans — Trigger automated tests on-demand from Azure Test Plans or as part of a CI/CD pipeline using the Visual Studio Test or Azure Test Plan task.
  • Track requirement quality — When test cases are linked to requirements (user stories, PBIs), automated test results flow through to show requirement-level quality. For more information, see Requirements traceability.
  • View results in Test Plans — See automated test pass/fail results alongside manual test results in the Test Run Hub.

Prerequisites

Category Requirement
Project access Project member.
Access levels - To view test-related work items or run test cases: At least Basic access. Users with Stakeholder access have no access to Test Plans.
- To exercise the full range of test-related features: Basic + Test Plans access level or one of the following Visual Studio subscriptions:
- Enterprise
- Test Professional
- MSDN Platforms
Permissions Area Path permissions:
- To add or modify test plans, test suites, test cases, or other test-based work item types: Edit work items in this node set to Allow.
- To modify test plan properties such as build and test settings: Manage test plans set to Allow.
- To create and delete test suites, add and remove test cases from test suites, or change test configurations associated with test suites: Manage test suites set to Allow.

Project-level permissions:
- To view, create, or delete test runs: View test runs, Create test runs, and Delete test runs set to Allow.
- To manage test configurations or test environments: Manage test configurations and Manage test environments set to Allow.
- To add new tags to test-based work items: Create tag definition set to Allow.
- To permanently delete test-based work items: Permanently delete work items set to Allow.

For more information, see Manual test access and permissions.

Supported test frameworks

The following table shows which test frameworks support association in Visual Studio and in Azure DevOps:

Framework Association in Visual Studio Association in Azure DevOps
MSTest v1/v2 Supported Supported
NUnit Supported Supported
xUnit Supported Supported
Selenium Supported Supported
Coded UI tests Supported Supported
Python (PyTest) Not supported Supported
Java (Maven and Gradle) Not supported Supported

Note

Tests that use the .NET Core framework can be associated with a test case when using Visual Studio 2017 version 15.9 or later. Specify the appropriate target framework in a .runsettings file.

Create a test project and build pipeline

  1. Create a test project containing your automated tests. For more information, see the supported frameworks table.
  2. Check your test project into Azure Repos or a connected GitHub repository.
  3. Create a build pipeline for your project that includes the automated tests. For more information, see Create your first pipeline.

Associate your automated test in Visual Studio

Use Visual Studio to associate automated tests with test cases when you:

  • Automate existing manual test cases — You created a manual test case and later wrote automated tests for the same scenario. Associating them lets you run the automated version from a test plan or CI/CD pipeline.
  • Enable end-to-end traceability — When test cases are linked to requirements, automated test results establish quality metrics for those requirements.
  1. Open your solution in Visual Studio 2017 or later (Enterprise or Professional edition).

  2. Locate the test case work item ID. You can find it in Azure Test Plans or by querying for the work item.

  3. In Test Explorer, select the test method you want to associate and choose Associate to Test Case.

    Note

    If Test Explorer isn't visible, open it from the Test menu. If your tests aren't displayed, build the solution first.

  4. In the dialog, enter the test case ID, select Add Association, and then select Save.

    Screenshot showing associating automation with test case.

Important

  • You can associate a test method with multiple test cases, but you can't associate more than one test method with a single test case.
  • Test case parameters are for manual test iterations only. Automated tests don't use parameters defined on the test case work item.

After you associate your tests, you can run them in build and release pipelines by using the Visual Studio Test task, or run them on-demand from Azure Test Plans. For more information, see Run automated tests from test plans.

Associate your automated test in Azure DevOps

You can also associate automated tests directly from the Azure DevOps web portal, without using Visual Studio. This approach supports all test frameworks, including Python and Java tests that can't be associated from Visual Studio.

Associate from a build pipeline

  1. Go to Pipelines and select a pipeline where your automated tests ran.

  2. Select the build run that contains the test results.

  3. On the Tests tab, find the automated test you want to link with a test case.

  4. Select the test and then select Associate Test Case.

  5. Find the test case you want to associate and select Associate.

    Screenshot showing the process of associating an automated test to a test case within a CI/CD pipeline interface.

Associate from a work item

  1. Open a test case work item and go to the Associated Automation tab.

  2. Select Browse.

  3. From the side panel, select the pipeline and the specific run where the test previously ran.

  4. Select the test you want to associate and select Associate test.

    Screenshot showing associating an automated test to a test case within a CI/CD pipeline interface.

After you associate your automated tests, you can run them as part of a pipeline by using the Azure Test Plan task or the Visual Studio Test task. For more information, see Run automated tests from test plans.

Automation Status field

The Automation Status field on the test case work item reflects whether the test case is linked to an automated test method:

  • Not Automated or Planned — Shown when the test case has no associated test method.
  • Automated — Shown when the test case has an associated test method.

If the default values don't match your organization's needs, you can create a custom pick-list field on the Test Case work item type.

FAQs

Q: Can I use tests from GitHub repositories?

A: Yes. As long as you run your automated tests in Azure Pipelines with the Visual Studio Test task or report the test results with the Publish Test Results task, the automated tests are available for association to test cases. The test must run at least once before it becomes available.

Q: Can I configure work items to open in Visual Studio?

A: Yes. To have test work items open in Visual Studio instead of the web browser, change the Work Items | General setting from the Tools | Options menu in Visual Studio.

Screenshot of Change work item display mode.