使用C#查找TFS中的所有子测试套件

时间:2018-09-06 02:48:14

标签: c# tfs

我想使用C#代码在TFS的父测试套件下获得所有子测试套件。让我知道是否有人这样做。

1 个答案:

答案 0 :(得分:0)

我已经基于Microsoft.TeamFoundationServer.ExtendedClient

创建了一个简单的应用程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string teamProjectName = "TFSCMMI";
            int parentTestSuiteId = 819; // or test plan id

            var TFSCurrentProjectCollection = new TfsTeamProjectCollection(new Uri("http://tfs-srv:8080/tfs/defaultcollection"));
            var testStore = TFSCurrentProjectCollection.GetService<ITestManagementService>();

            var teamProject = testStore.GetTeamProject(teamProjectName);

            var testSuite = teamProject.TestSuites.Find(parentTestSuiteId);
            if (testSuite.TestSuiteType == TestSuiteType.StaticTestSuite)
            {
                var staticSuite = testSuite as IStaticTestSuite;
                foreach (var childSuite in staticSuite.Entries)
                {
                    Console.WriteLine("Test suite id " + childSuite.Id + " name '" + childSuite.Title + "'");
                }
            }
        }
    }
}