Find all test cases which contain parameters for a given plan and suite
A customer was interested in reporting on parameterized test cases present in a test plan. Here is a powershell script that lists the number of parameters,and the number of iterations for all test cases present within a given plan and suite:
# Load Client Assembly
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.Client, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.TestManagement.Client, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.TestManagement.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
# Define parameters
$tfsCollectionUrl = “ https://myserver:8080/tfs/DefaultCollection”;
$projectName = "DefaultProject";
$planId = "1";
$suiteId = "7"; ;
# Connect to tfs
$tfsCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionUrl);
$tcmService = $tfsCollection.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService]);
[Microsoft.TeamFoundation.TestManagement.Client.ITestManagementTeamProject] $tcmProject = $tcmService.GetTeamProject($projectName);
# Query for test plan/points
$testPlansProperty = [Microsoft.TeamFoundation.TestManagement.Client.ITestManagementTeamProject]. GetProperty("TestPlans").GetGetMethod();
$testPlans = $testPlansProperty.Invoke($tcmProject, "instance,public", $null, $null, $null);
$testPlan = $testPlans.Find($planId);
$pointsQueryWiql = [string]::Format("SELECT * FROM TestPoint WHERE SuiteId={0}", $suiteId);
$testPoints = $testPlan.QueryTestPoints($pointsQueryWiql);
foreach($testPoint in $testPoints){
$testCase = $testPoint.TestCaseWorkItem;
$parametersCount = $testCase.TestParameters.Count;
Write-Host("----------------------------------");
Write-Host([string]::format("Id:{0} Title:{1}", $testCase.Id,$testCase.Title));
Write-Host ("Parameters count: {0}" -f ($parametersCount));
Write-Host ("Is test case parameterized: {0}" -f ($parametersCount -gt 0));
if($parametersCount -gt 0){
Write-Host("Iteration count: {0}" -f $testCase.Data.Tables[0].Rows.Count);
}
}