user963491
user963491

Reputation: 151

TFS how can I get test parameters for a test

I'm going over all test cases under a specific test plan, and for each test case I want to print the parameter name and values.

foreach(var param in test.TestParameter)
{

}

The problem is that item.Value is null. item.Name returns the parameter name. Does anyone knows how to get the values of a parameter?

Thanks.

Upvotes: 0

Views: 2017

Answers (3)

Majdi Barrat
Majdi Barrat

Reputation: 161

with this code you can get all parameter for a test case as a DataRow[]

TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFS_URL"));
ITestManagementTeamProject project = tfs.GetService<ITestManagementService>().GetTeamProject("ProjectName");
var testCase = project.TestCases.Find(1234);
var testData = testCase.Data.Tables[0];
this._dataSource = testData.Select();

If you want to get the parameters with attributes, you can see my repository on GitHub Click here!

Upvotes: 2

brakertech
brakertech

Reputation: 1477

Since I banged my head against the wall to figure this out in powershell I thought I'd share it with everyone:

$ProjectName = "foo"
$TfsServerUrl = "http://tfsserverurl:8080/tfs/bar"
$testPlanName = "testplanname"

#===================================================
#     Settings
#===================================================

Write-Host "Input parameters: "
$ParamObject = @{
 'ProjectName' = $ProjectName;
 'TfsServerUrl' = $TfsServerUrl;
 'testPlanName' = $testPlanName;
}
$ParamObject | Format-Table

#===================================================
#    Main Script Body
#===================================================

  #load assemblies
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.TestManagement.Common")
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.TestManagement.Client")
    #get TFS structure, project
 $tfs = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection([Microsoft.TeamFoundation.Client.TfsTeamProjectCollection]::GetFullyQualifiedUriForName($tfsServerUrl));
 $tms = $tfs.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService]);
 $project = [Microsoft.TeamFoundation.TestManagement.Client.ITestManagementTeamProject]$tms.GetTeamProject($ProjectName);
 #powershell bug workaround, $project.TestPlans property is not available
 $testPlansProperty = [Microsoft.TeamFoundation.TestManagement.Client.ITestManagementTeamProject].GetProperty("TestPlans").GetGetMethod();
 $testPlans = $testPlansProperty.Invoke($project, "instance,public", $null, $null, $null);
#   List all Test Plans
 foreach($p in $testPlans.Query("Select * From TestPlan"))
 {
  "Plan - {0} : {1}" -f $p.Id, $p.Name
 }
 $currentPlan = $testPlans.Query("Select * From TestPlan Where planName = '{0}'" -f $testPlanName)
 $plan = $currentPlan | where {$_.Name -eq $testPlanName}

 $testCases = $plan.RootSuite.AllTestCases


 foreach($testCase in $testCases)
 {
  write-host ""
  write-host "-----------"
  write-host "START - Test Case"  $testCase.Id
   write-host "Parameters:"

$testCase.TestSuiteEntry.TestCase.DefaultTable  
  write-host "-----------"
}

Upvotes: 0

cerezza
cerezza

Reputation: 251

Test parameter values are stored in TestCase objects TestSuiteEntry attribute. You can call it by TestSuiteEntry.TestCase.DefaultTable.Rows[0].ItemArray

Upvotes: 2

Related Questions