如果您所創建的測試套件和mtmTestSuite:
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測試套件」在創建testSuite並添加到測試計劃/套件後,您只需添加一行代碼即可將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);
謝謝你的幫助!但是你的邏輯假設我在我的計劃中只有一個測試套件 - >(First())。如果我有很多測試套件,並且想爲其中一些測試套件創建子測試套件(測試套件),我該怎麼辦? –