TFS如何获得测试的测试参数

时间:2012-07-13 20:51:52

标签: c# tfs2010 tfs-sdk

我将根据特定的测试计划查看所有测试用例,并且对于每个测试用例,我想打印参数名称和值。

foreach(var param in test.TestParameter)
{

}

问题是item.Value为null。 item.Name返回参数名称。 有谁知道如何获取参数的值?

感谢。

3 个答案:

答案 0 :(得分:2)

测试参数值存储在TestCase对象的TestSuiteEntry属性中。 您可以通过TestSuiteEntry.TestCase.DefaultTable.Rows[0].ItemArray

来调用它

答案 1 :(得分:2)

使用此代码,您可以将测试用例的所有参数作为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();

如果要获取带有属性的参数,则可以在GitHub上查看我的存储库。单击here

答案 2 :(得分:0)

因为我把头撞在墙上以便在PowerShell中解决这个问题,我以为我会和所有人分享:

$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 "-----------"
}