How to migrate MTM Test Cases from TFS 2013 to VSTS?

我的梦境 提交于 2019-12-01 01:31:57

For a one-shot migration I can suggest a couple of options:

  1. From the test hub in your on-premises web access, create a test plan including all the test cases and then switch to the grid view in the main pane. There you can select and copy all test cases (including steps, expected results and other test case fields) and paste them into the equivalent view in the VSTS project.

  2. Create a powershell script that gets all the test cases from your on-premises TFS and copies them into VSTS. Below you can find a snippet. Caveat: I have not tested it extensively, so usual disclaimers apply. Please add additional fields you may want to copy.

    $VerbosePreference = "Continue"
    
    $tfsSource="the collection url that you want to copy form (eg. http://yourserver/tfs/yourcollection)";
    $tpSource="the team project containing the test cases you want to copy form";
    
    $tfsDest="the collection url that you want to copy to (eg. https://youraccount.visualstudio.com/DefaultCollection");
    $tpDest="the team project containing the test cases you want to copy to";
    
    
    [Reflection.Assembly]::LoadWithPartialName(‘Microsoft.TeamFoundation.Client’)
    [Reflection.Assembly]::LoadWithPartialName(‘Microsoft.TeamFoundation.TestManagement.Client’)
    [Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\Newtonsoft.Json.dll")
    
    $sourceTpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsSource)
    $sourceTcm = $sourceTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
    $sourceProject = $sourceTcm.GetTeamProject($tpSource);
    $sourceTestCases = $sourceProject.TestCases.Query(“SELECT * FROM WorkItem”);
    
    $destTpc= [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsDest)
    $destTcm = $destTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
    $destProject = $destTcm.GetTeamProject($tpDest);
    
    
    foreach ($tc in $sourceTestCases)
    {
        Write-Verbose ("Copying Test Case {0} - {1}" -f $tc.Id, $tc.Title)
        $destTestCase= $destProject.TestCases.Create();
        $destTestCase.Title = $tc.Title;
        $destTestCase.Priority = $tc.Priority;
    
        foreach ($step in $tc.Actions)
        {
            $destStep= $destTestCase.CreateTestStep();
    
            $destStep.Title= $step.Title
            $destStep.TestStepType= $step.TestStepType
            $destStep.Description= $step.Description
            $destStep.ExpectedResult=  $step.ExpectedResult;
            $destTestCase.Actions.Add($destStep);
        }
        $destTestCase.Save();
    }
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!