簡體   English   中英

Powershell-將測試用例從TFS遷移到Azure DevOps的腳本

[英]Powershell - script to migrate test cases from TFS to Azure DevOps

我正在嘗試使用腳本將特定項目的測試用例從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();
}

我建議您在查詢工作項時編寫Where查詢。

WHERE [System.TeamProject] = '" + teamProject.Name

您可以在查詢中添加Where project = '@Project' ,以將范圍限制為僅該項目。 先調用BeginQuery然后EndQuery你會得到一個workitem集合只是你正在尋找的項目。

獲取所需wql查詢的最簡單方法是在Team Explorer中創建查詢,然后使用file-> save as(在編輯模式下)將其保存到文件中。 在記事本中打開該文件,將查詢復制到那里。

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM