Associate automated tests with test cases

Visual Studio 2019 | Visual Studio 2017

Consider using Visual Studio to associate automated tests with a test case when:

  • You created a manual test case that you later decide is a good test to automate, but you still want to be able to run that test as part of a test plan. Tests can be run in the CI/CD pipeline by choosing the test plan or test suite in the settings of the Visual Studio Test task. Automated tests can also be run from Azure Test Plans or the Test hub in TFS (see Web portal navigation). If you are using XAML builds you can also run these automated tests by using Microsoft Test Manager.

  • You want to enable end-to-end traceability of requirements. If your test cases are linked to requirements or user stories, the results of the test execution can be used to establish the quality of those requirements.

The process to associate an automated test with a test case is:

  1. Create a test project containing your automated test. What types of tests are supported?

  2. Check your test project into an Azure DevOps or Team Foundation Server (TFS) repository.

  3. Create a build pipeline for your project, ensuring that it contains the automated test. What are the differences if I am still using a XAML build?

  4. Use Visual Studio Enterprise or Professional 2017 or a later version to associate the automated test with a test case as shown below. The test case must have been added to a test plan that uses the build you just defined.

If you are using the build and release services in Azure DevOps or TFS (not a XAML build), you can run associated tests in the build and release pipelines by using the Visual Studio Test task. You cannot run tests on-demand using Microsoft Test Manager unless you are using a XAML build.

The parameters in a test case are not used by any automated test that you associate with a test case. Iterations of a test case that use these parameters are for manual tests only.

For more information about checking in your test project and team build, see Add files to the server and Continuous integration on any platform. For more information about action recordings and coded UI tests, see Recording and Playing Back Manual Tests and Use UI Automation To Test Your Code.

Associate your test

  1. Open your solution in Visual Studio Enterprise or Professional 2017 or a later version.

  2. If you don't know the identifier of the work item for the test case, locate the test case in Azure Test Plans or the Test hub in TFS, or query for the work item in the Work hub.

  3. When you know the identifier of the work item for the test case:

    If you are using Visual Studio 2017 or later, follow these steps to associate your tests.

    • If the Test Explorer window is not displayed, open it from the Test | Windows menu.

    • If your tests are not displayed in Test Explorer, build the solution.

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

    • In the dialog that opens, type the test case identifier and choose Add Association, then choose Save.

    Associate Automation With Test Case

    The dialog shows a list of test cases currently associated with the selected test method. You cannot associate more than one test method with a test case, but you can associate a test method with more than one test case.

FAQ

Q: What types of tests are supported?

A: These are the limitations for each type of test:

  • Coded UI test, Selenium tests, and unit tests written using Version 1 of the MSTest framework can be associated with a test case.
  • Tests that use MSTest v2, NUnit, and xUnit frameworks can be associated with a test case workitem when using Visual Studio 15.9 Preview 2 or later. However, these tests cannot be run using Microsoft Test Manager and XAML builds.
  • Tests that use the .NET core framework can be associated with a test case workitem when using Visual Studio 15.9 Preview 2 or later. To run the .NET core tests the appropriate target framework must be specified in a runsettings file. However, these tests cannot be run using Microsoft Test Manager and XAML builds.
  • Tests that use other test frameworks such as Chutzpah (for JavaScript tests such as Mocha or QUnit), or Jest cannot be associated with a test case.
  • Associating generic tests may work, but running these tests is not supported.

Q: What are the differences if I am still using a XAML build?

A: If you are using a XAML build in Azure Pipelines or TFS, you can run tests that you have associated in a Build-Deploy-Test workflow using a Lab environment. You can also run tests using Microsoft Test Manager and a Lab environment.

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

A: Yes, if you want test work items to open inside Visual Studio instead of the default Azure Pipelines or TFS UI in your web browser, change the Work Items | General setting from the Tools | Options menu in Visual Studio.

Change work item display mode

See Also

Help and support

Report any problems on Developer Community, get advice on Stack Overflow, and get support via our Support page.