美好的一天!
我尝试在测试计划tfs 2010上解析树。
所以,我可以获得测试计划:
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();
}
然后我需要解析SubTree:
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);
}
}
所以,我解析了一个新的子树元素,但我知道,在那个节点后我有另一个节点。就像这样:
Root:element1,element2,element3 ...
--- Node1:element1,element2 ....
-------- Node2:element1,element2 ...
但是planOld.RootSuite.SubSuites.Count == 1;我只看到Root和Node1的元素。
另一个问题是创建新的子树: 这段代码不起作用:
planNew.RootSuite.SubSuites.Add(suiteNew); // cannot add,remove item error.
请帮我解析一下! 为什么我不能在树上添加子节点?
谢谢!
答案 0 :(得分:2)
这是您在测试计划下创建新测试套件的方法
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();
对于第一个问题,我真的不明白也许你可以解释更多。