繁体   English   中英

如何通过TFS API检索测试计划中的所有测试用例?

[英]How to retrieve all Test Cases in a Test Plan via TFS API?

我正在尝试使用TFS 2015 API将所有测试用例都放在一个测试计划下。 我目前遇到的问题是,我要在测试计划中检索所有测试用例,但是我提取测试用例的方式是让我在测试计划中收集不同的测试用例。 我想要所有测试用例ID,包括重复的测试用例ID,以备我们在该测试计划中测试特定测试的各种配置时使用。

我最终希望能够通过API访问测试用例的所有配置结果。

以下是我用于获取指定测试计划ID的测试用例的方法:

public ITestCaseCollection
TestPlan_GetAllTestCasesByPlanId(ITestManagementTeamProject testproject, int id)
{
    var plans = testproject.TestPlans.Query("Select * From TestPlan");
    var planById = plans.First(x => x.Id == id);
    return planById.RootSuite.AllTestCases;
}

假设我有一个包含10个不同测试用例的测试计划,每个用例有两种不同的配置。 因此,该计划现在最终将有20个测试用例场景,在测试运行期间将有20种可能的结果。 使用以上方法,它仅拉入10个不同的测试用例。

我尝试使用以下方法ITestSuiteEntry计划中的每个ITestSuiteEntry ,但它仅会直接影响计划中的套件。 它不考虑嵌套套件。

public ITestCaseResultCollection GetTestCaseResults(ITestManagementTeamProject testproject, int id)
{
    var plans = testproject.TestPlans.Query("Select * from TestPlan");
    var planById = plans.First(x => x.Id == id);

    foreach(ITestSuiteEntry suiteEntry in planById.RootSuite.Entries)
    {
        var testSuite = suiteEntry.TestSuite;
        foreach(ITestSuiteEntry subSuiteEntry in testSuite.TestCases)
        {    
            var testCaseResults = testproject.TestResults.ByTestId(subSuiteEntry.TestCase.Id);
        }
    }
}

如何访问计划中每个测试用例的每个配置,以便收集它们的测试结果? 有什么明显的我想念的地方吗?

您可以尝试使用以下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 "-----------"
}

参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM