2

我正在尝试使用 TFS API 为 TestPlan 获取特定的 TestSuite。

TestSuite 可以存在于 TestSuite 层次结构中的任何位置,因此,我当然可以编写一个递归函数。但是,我想要更有效的东西。

有没有我遗漏的方法,或者我可以写一个查询?

4

1 回答 1

5

如果你已经知道testSuiteId事情很简单。您只需要知道 TeamProject 的名称teamProjectName

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;

namespace GetTestSuite
{
    class Program
    {
        static void Main()
        {
           int testSuiteId = 555;
           const string teamProjectName = "myTeamProjectName";

           var tpc =
                TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
                    new Uri("http://tfsURI"));

           var tstService = (ITestManagementService)tpc.GetService(typeof(ITestManagementService));
           var tProject = tstService.GetTeamProject(teamProjectName);

           var myTestSuite = tProject.TestSuites.Find(testSuiteId);            
        }
    }
}

如果您不这样做,您可能需要寻求类似于此处介绍的解决方案(这是 S.Raiten 的帖子),其中递归确实出现了。testPlanId假设访问 a :

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;

namespace GetTestSuite
{
    class Program
    {
        static void Main()
        {
            int testPlanId = 555;
            const string teamProjectName = "myTeamProjectName";

            var tpc =
                TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
                    new Uri("http://tfsURI"));

            var tstService = (ITestManagementService)tpc.GetService(typeof(ITestManagementService));
            var tProject = tstService.GetTeamProject(teamProjectName);

            var myTestPlan = tProject.TestPlans.Find(testPlanId);
            GetPlanSuites(myTestPlan.RootSuite.Entries);                
        }

        public static void GetPlanSuites(ITestSuiteEntryCollection suites)
        {
            foreach (ITestSuiteEntry suiteEntry in suites)
            {
                Console.WriteLine(suiteEntry.Id);
                var suite = suiteEntry.TestSuite as IStaticTestSuite;
                if (suite != null)
                {
                    if (suite.Entries.Count > 0)
                        GetPlanSuites(suite.Entries);
                }
            }
        }
    }
}
于 2012-04-24T14:44:36.730 回答