如何使用powershell将参数从tfs测试用例克隆到vsts

时间:2017-10-27 13:37:14

标签: powershell tfs migration azure-devops

您好我有一个powerShell脚本,它将使用从TFS2012到VSTS的参数克隆测试用例,但我无法获取要克隆的参数值。

第一部分只是确定了两个项目的位置

$VerbosePreference = "Continue"

$tfsSource="http://server:8080/tfs/DefaultCollection/";
$tpSource="My Project in TFS";

$tfsDest="https://server.visualstudio.com:443";
$tpDest="My Project in VSTS";


[Reflection.Assembly]::LoadWithPartialName(‘Microsoft.TeamFoundation.Client’)
[Reflection.Assembly]::LoadWithPartialName    (‘Microsoft.TeamFoundation.TestManagement.Client’)
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Microsoft Visual  Studio 14.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”);
 $sourceTestCases = $sourceProject.TestCases.Query(“SELECT * FROM WorkItem  where State = 'Ready' AND Title contains 'Parameter Test'");

$destTpc=  [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsDest)
$destTcm = $destTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$destProject = $destTcm.GetTeamProject($tpDest);

#The next steps will copy the test case steps from old project to the new project 

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

#The next steps bring in the parameters.  This is where the problem is.

    foreach ($pv in $tc."Parameters")
{
    $destpv= $destTestCase.CreateParameterValue();

    $destpv."Parameter value"=  $pv."Parameter value";

    $destTestCase.Actions.Add($destpv);
}

$destTestCase.Save();
}

1 个答案:

答案 0 :(得分:0)

ITestCase($ tc)中没有Parameters属性,而是使用此代码复制参数的数据:

  #......
#The next steps bring in the parameters.  This is where the problem is.

    #    foreach ($pv in $tc."Parameters")
    #{
    #    $destpv= $destTestCase.CreateParameterValue();

    #    $destpv."Parameter value"=  $pv."Parameter value";

    #    $destTestCase.Actions.Add($destpv);
    #}

    $ts = $tc.Data.Tables;

      for($tri=0;$tri -lt $ts[0].Rows.Count;$tri++)
      {
        $newRow=$destTestCase.Data.Tables[0].NewRow()
        foreach($tc in $ts[0].Columns)
        {
          $newRow[$tc.ColumnName]=$ts[0].Rows[$tri][$tc]
        }

        $destTestCase.Data.Tables[0].Rows.Add($newRow)
      }

    $destTestCase.Save();
相关问题