Options for Copying Test Cases in TFS
I recently had a customer ask if they could “copy” test cases in Microsoft Test Manager. As with many questions, the answer is the all too fearsome, “it depends” and more context is needed to properly answer the question. In this post, I thought I’d try to describe the options for “copying” test cases and provide some sample use cases.
Re-using a test case
Within a test plan, you can place the same test case in multiple test suites. These “copies” are the same test case and any changes you make to this test case will be evident no matter which test suite you open or run it from.
Copying a test case – This is also known as a “shallow copy”
You can copy test cases from one test plan to another. When copying test cases, you create a copy of all test cases in one test suite and add them to another test suite. As with the above option, these are really the same test cases, so any change you make to one, you will make to the other. The attributes and test steps are all “shared”, however test results are not.
Note that the source and destination test suites are independent of each other. You can add or remove test cases from either of them without affecting the other.
- From the Plan tab, select a static test suite that will hold the new copy.
- In the toolbar, click the button Create test suites by referencing existing test cases.
- In the dialog window, select the test plan and test suite that you want to copy, and click Create suite.
- When you are beginning a new iteration or project, you may want re-use existing test cases from previous efforts.
Cloning a test case – This is sometimes known as a “deep copy”
You can clone test cases to create an independent copy of an existing test case. After cloning, you can make changes to either the original or cloned test case without affecting the other.
Note that cloning can be used across Team Projects, but not across Team Project Collections.
Note that this creates a whole new test plan.
- From the Organize tab, select a test plan.
- In the toolbar, click the button labeled Clone.
- In the dialog window, select one or more test suites from the drop down list that you want to clone.
- (Optional) Check the box labeled Clone requirements to also “deep copy” any requirements associated with the selected test suite(s).
- On the right side of the dialog, enter the name of the destination test plan, and set the associated area path and iteration path.
- Click the Clone button.
- The Clone log appears. Pay close attention to the status of each cloning operation as it may take a few moments to complete.
- Open a command prompt.
- Type cd %VS110COMNTOOLS%..\IDE to navigate to the necessary directory
Type tcm suites /clone /collection:http://YourServer:8080/tfs/YourCollection /teamproject:”YourSourceProject” /destinationTeamProject:”YourDestinationProject” /suiteid:YourSourceSuite /destinationsuiteid:YourDestinationSuite /clonerequirements /overridefield:”YourField“=”YourValue“
- YouServer– the name of your Team Foundation Server
- YourCollection– the name of your Team Project Collection
- YourSourceProject– the name of the Team Project you want to clone from
- YourDestinationProject – the name of the Team Project you want to clone to; this is an optional parameter and you do not need to use it if you are cloning within the same Team Project
- YourSourceSuite – the ID of the test suite to be cloned; the ID is displayed in the details pane when you select it in the test plan; retrieve a list of suites by using tcm /suites /list; nested test suites will be cloned as well
- YourDestinationSuite – the ID of the test suite you want to clone to
- *clonerequirements – this is an optional parameter and you use it if you want to clone the requirement work items used by requirements-based suites; if this parameter is not specified, requirements-based suites will be converted to static suites
- *overridefield – this is an optional parameter and you use it if you want to set a particular field in the new test cases
- Clone test cases when you want to use the same test case against two releases simultaneously. This way you can edit the test case for one release without interfering with the efforts in the other release.
Use a test case as a template to create a new test case
You can use an existing test case to create a new test case with all of the same values.
- From the Plan tab, right-click a test case, and select Create copy and add to suite.
- When you have a number of test case properties (e.g. iteration path, area path, priority, etc.) that will have the same values in your new test case, you can use an existing test case as the starting point.
- Similarly, when you have a complicated or lengthy number of test steps in an existing test case that will be repeated in a new test case. (You should also consider Shared Steps in this use case.)
There’s a growing number of Microsoft Test Manager/TFS users out there, so I hope this helps you.