Recently I was helping a client of SMEx Digital to migrate their VSTS projects. One of the requirements was also retain their ~450 test cases that they have built up.
VSTS gives you hope in the Queries interface by providing an option to "Move to team project..."
However this doesn't work for Test Cases as they are classed as hidden and you will get an error message if you try.
Thankfully, if you have Microsoft Test Manager installed, then you have access to Test Case Management CLI (tcm.exe)
To migrate test cases from one project to another, what you have to do is:
- Select Test | Test Plans
- Create a new Test Plan (call it All Test Cases)
- Create a new Query Based Test Suite (call it All Test Cases)
- For the Query, just use "Work Item Type" "In Group" "Microsft.TestCaseCategory"
- Select all your test cases and Create Suite
- You need to note the Test Suite ID as we'll need this in the command line later. I'll refer to this as the <SourceSuiteID>
Now in your destination Team Project (<TargetProjectName>)
- Create a new Test Plan called Imported Test Cases
- Note the Suite ID of this test plan. I'll refer to this as the <TargetSuiteID>
Now fire up the Developer command prompt
C:\Users\ephan>tcm suites /clone /collection:https://<youraccount>.visualstudio.com/defaultcollection /teamproject:<SourceProjectName> /suiteid:<SourceSuiteId> /destinationteamproject:"<TargetProjectName>" /destinationsuiteid:<TargetSuiteId> /overridefield:"Iteration Path"="<TargetProjectName>)" /overridefield:"Area Path"="<TargetProjectName>" Started clone operation with id 1. Use /status:1 to get progress and completion information of the operation. Warning: You have cloned the following query based suites as part of this clone operation. You are advised to fix their respective queries in the source and destination suites, after the clone operation completes. 1. All Test Cases -> All Test Cases
It should give you an operation id which you use to query the status of the job.
C:\Users\ephan>tcm suites /status:<Operation ID> /clone /collection:https://<youraccount>.visualstudio.com/defaultcollection /teamproject:<SourceProjectName> Clone operation 1 is in progress. Total test cases: 446 Processed: 198 Progress: 44% C:\Users\ephan>tcm suites /status:<Operation ID> /clone /collection:https://<youraccount>.visualstudio.com/defaultcollection /teamproject:<SourceProjectName> Clone operation 1 has succeeded. Summary information: Started on: 3/01/2018 3:26:24 PM Started by: Eric Phan Source suite id: 20105 Destination suite id: 20579 Test cases cloned: 446 Shared steps cloned: 24 Requirements cloned: 0 Completed on: 3/01/2018 3:28:36 PM
Now if we go over to the target project and query the test cases, we can see that they've all been imported.
Note: This only works when you want to migrate within the same VSTS instance/collection