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

前端 未结 1 1672
别那么骄傲
别那么骄傲 2021-01-07 09:59

We have a legacy of thousands of manual Test Cases created in Microsoft Test Manager in our on premises TFS 2013.

We are trying to

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-07 10:08

    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();
      }
      

    0 讨论(0)
提交回复
热议问题