Associate automated tests with test cases
Visual Studio 2017 | Previous version
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 the Test hub in VSTS and TFS. 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:
Create a test project containing your automated test. What types of tests are supported?
Check your test project into a VSTS or Team Foundation Server (TFS) repository.
Create a build definition for your project, ensuring that it contains the automated test. What are the differences if I am still using a XAML build?
Use Visual Studio Enterprise, Visual Studio Professional, or Visual Studio Test Professional 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 Team Foundation Build and Release Management in VSTS or TFS (not a XAML build), you can run associated tests in the Build and Release pipeline by using the Visual Studio Test task. You cannot run tests on-demand using Microsoft Test Manager (MTM) 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
Open your solution in Visual Studio.
If you don't know the identifier of the work item for the test case, locate the test case in the Test hub or query for the work item in the Work hub.
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.
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.
If you are using Visual Studio 2015 or earlier, follow these steps to associate your tests.
In Team Explorer open the Work Items tab. If the Team Explorer window is not displayed, open it from the View menu.
Expand the list of Queries in the Work Items tab to find one that displays your test cases, for example the default My Test Cases query.
Execute the query by choosing View Results on the shortcut menu (or double-click the query name).
Open the test case you want to associate by choosing Open on the shortcut menu (or double-click the test case name).
In the work item, open the ASSOCIATED AUTOMATION tab. All the tests in the solution are shown in the list together with their associated test projects.
Choose the ellipsis (...) and, in the Choose Test dialog, select the test and then choose OK. The value in Automation Status is automatically changed to Automated.
Choose Save Work Item to save the changes to the test case.
If a test case already has an automated test associated with it, you must first remove this association before you can add a different automated test. Choose Remove association to remove the existing automation.
- Associate automated test results with requirements
- Run automated tests from test plans in the Test hub
- Run automated tests with Microsoft Test Manager
- Test with unified agents and phases
- Continuous testing scenarios and capabilities