这是第一步
IStaticTestSuite testSuite = _teamProject.TestSuites.CreateStatic();
// create an empty test suite below
IStaticTestSuite mtmTestSuite = _teamProject.TestSuites.CreateStatic();
我想在mtmTestSuite
里面添加,testsuite
因为我们可以手动添加。
试试下面的代码:
ITestPlanCollection plans = testproject.TestPlans.Query("Select * From TestPlan");
var p = plans.Where(pp => pp.Name == "Plan1").First();
IStaticTestSuite newSuite = testproject.TestSuites.CreateStatic();
newSuite.Title = "Acceptance Tests";
IStaticTestSuite pSuite = p.RootSuite.Entries.Where(s => s.Title == "WindowsFormDemoTest").First().TestSuite as IStaticTestSuite;
pSuite.Entries.Add(newSuite);
// p.RootSuite.Entries.Add(newSuite);
p.Save();
您可以通过以下链接引用“添加新 TFS 测试套件”部分的更多方法:管理 TFS 测试套件 C# 代码
如果您同时创建 testSuite 和 mtmTestSuite,您只需要在 testSuite 创建并添加到 Test Plan/Suite 后添加一行代码即可将 mtmTestSuite 添加到 testSuite 中:
testSuite.Entries.Add(mtmTestSuite);
如果 testSuite 已经存在,那么您需要先获取 testSuite,然后将 mtmTestSuite 添加到其中。例如:
IStaticTestSuite testSuite = itmtp.TestSuites.CreateStatic();
foreach (IStaticTestSuite ts in itmtp.TestSuites.Query("Select * From TestSuite"))
{
if (ts.Id == 103)//Get the test suite by ID
{
testSuite = ts;
}
}
IStaticTestSuite mtmTestSuite = itmtp.TestSuites.CreateStatic();
mtmTestSuite.Title = "Title";
testSuite.Entries.Add(mtmTestSuite);