如何从TFS测试计划中解析树

本文关键字:测试计划 TFS | 更新日期: 2023-09-27 17:59:44

您好!

我试图解析测试计划tfs2010中的树。

所以,我可以得到测试计划:

var planOld = helperOldProject.GetTestPlan("TestProject", 10); // 10- id of test plan
ITestManagementTeamProject project1 = helperNewProject.GetProject(sourceserverurl,    sourceproject);

然后我用程序创建了新的测试计划:

//Create a Test Plan Programmatically
 ITestPlan planNew = project1.TestPlans.Create();
        planNew.Name = planOld.Name;
        planNew.StartDate = DateTime.Now;
        planNew.EndDate = DateTime.Now.AddMonths(2);
        planNew.AreaPath = "TestArea";
        planNew.Description = planOld.Description;
        planNew.State = planOld.State;
        // other attributes: plan.AreaPath, plan.Description,plan.State
        planNew.Save();
        And then i need to parse RootSuite tree:
        var suiteOld = planOld.RootSuite;
        // Parse Root:
        IStaticTestSuite suiteNew = project1.TestSuites.CreateStatic();
         suiteNew.Title = suiteOld.Title;
         planNew.RootSuite.Entries.Add(suiteNew);
         foreach (var tcc in suiteOld.TestCases)
         {
             var tc = helperOldProject.teamProject.TestCases.Find(tcc.Id);
             var tc2 = helperNewProject.teamProject.TestCases.Create();
             tc2.Description = tc.Description;
             tc2.Owner = tc.Owner;
             tc2.Title = tc.Title;
             tc2.Save();
             suiteNew0.Entries.Add(tc2);
             planNew.Save();
         }

然后我需要解析子树:

          CreateSubTree(ref project1,ref planOld,ref planNew,ref helperOldProject,ref helperNewProject);
           public static void CreateSubTree(ref ITestManagementTeamProject project1,ref ITestPlan planOld, 
       ref ITestPlan planNew,ref Helper helperOldProject,ref Helper helperNewProject)
    {

        Console.WriteLine("SubSuites.Count: " + planOld.RootSuite.SubSuites.Count);
        foreach (ITestSuiteBase suiteOld in planOld.RootSuite.SubSuites)
        {
            IStaticTestSuite suiteNew = project1.TestSuites.CreateStatic();
            // planNew.RootSuite.SubSuites.Add(suiteNew);
            IStaticTestSuite staticSuiteOld = suiteOld as IStaticTestSuite;

            foreach (ITestSuiteEntry tccOld in staticSuiteOld.TestCases)
            {
                suiteNew.Title = suiteOld.Title;
                planNew.RootSuite.Entries.Add(suiteNew);
                //planNew.RootSuite.SubSuites.Add(suiteNew);
                var tc = helperOldProject.teamProject.TestCases.Find(tccOld.Id);
                var tc2 = helperNewProject.teamProject.TestCases.Create();
                tc2.Description = tc.Description;
                tc2.Owner = tc.Owner;
                tc2.Title = tc.Title;
                tc2.Save();
                suiteNew.Entries.Add(tc2);
            }
            Console.WriteLine(suiteOld.TestSuiteEntry);
        }
    }

所以,我解析新的一个子树元素,但我知道,在那个节点之后,我有另一个节点。像这样:

根:元素1,元素2,元素3。。。

---节点1:element1,element2….

--------Node2:element1,element2…

但是planOld.RootSuite.SubSuite.Count==1;我只看到Root和Node1的元素。

另一个问题是创建新的子树:此代码不起作用:

planNew.RootSuite.SubSuites.Add(suiteNew);  // cannot add,remove item  error.

请帮我解析一下!为什么我不能在树上添加子节点?

谢谢!

如何从TFS测试计划中解析树

这就是在测试计划下创建新测试套件的方法

        ITestManagementTeamProject teamProject = testManagementService.GetTeamProject(projectId);
        ITestPlan testplan= teamProject.TestPlans.Find(testplanId);
        IStaticTestSuite newSuite = teamProject.TestSuites.CreateStatic();
        newSuite.Title = "new title";
        testplan.RootSuite.Entries.Add(newSuite);
        testplan.Save();

对于第一个问题,我真的不明白,也许你可以解释更多。