我正在尝试使用脚本将特定项目的测试用例从TFS迁移到Azure DevOps。但是,即使我指定了一个项目,它也会从所有项目中选择测试用例。
$VerbosePreference = "Continue"
$tfsSource="http://tfsportal.lionbridge.com/tfs/TFSCollection01";
$tpSource="VDB";
$tfsDest="https://liox-teams.visualstudio.com";
$tpDest="TestCaseMigrationTest";
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.TestManagement.Client.dll"
[Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Client')
[Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.TestManagement.Client')
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PrivateAssemblies\Newtonsoft.Json.9.0.0.1\Newtonsoft.Json.dll")
$sourceTpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsSource)
[switch] $refresh
$sourceTcm = $sourceTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$sourceProject = $sourceTcm.GetTeamProject($tpSource);
$sourceTestCases = $sourceProject.TestCases.
$sourceTestCases = $sourceProject.TestCases.Query("SELECT * FROM WorkItem");
$destTpc= [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsDest)
[switch] $refresh
$destTcm = $destTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$destProject = $destTcm.GetTeamProject($tpDest);
foreach ($tc in $sourceTestCases)
{
Write-Verbose ("Copying Test Case {0} - {1} :- {2}" -f $tc.Id, $tc.WorkItem.AreaPath, $tc.Title)
$destTestCase= $destProject.TestCases.Create();
$destTestCase.Title = $tc.Title;
$destTestCase.Priority = $tc.Priority;
$destTestCase.State = $tc.State
$destTestCase.Reason = $tc.Reason
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)
我建议您在查询工作项时编写Where查询。
WHERE [System.TeamProject] = '" + teamProject.Name
您可以在查询中添加Where project = '@Project'
,以将范围限制为该项目。首先调用BeginQuery
,然后再调用EndQuery
,您将得到一个workitem
集合,其中仅包含您要查找的项目。
获取所需wql查询的最简单方法是在Team Explorer中创建查询,然后使用file-> save as(在编辑模式下)将其保存到文件中。在记事本中打开该文件,将查询复制到那里。
希望有帮助。