2016-06-29 46 views
0

這裏建立一間套房另一套房在微軟測試經理裏面是第一步如何使用API​​

IStaticTestSuite testSuite = _teamProject.TestSuites.CreateStatic(); 
// create an empty test suite below 
IStaticTestSuite mtmTestSuite = _teamProject.TestSuites.CreateStatic(); 

我想補充mtmTestSuitetestsuite我們可以做手工。

回答

0

嘗試用下面的代碼:Manage TFS Test Suites C# Code

+0

謝謝你的幫助!但是你的邏輯假設我在我的計劃中只有一個測試套件 - >(First())。如果我有很多測試套件,並且想爲其中一些測試套件創建子測試套件(測試套件),我該怎麼辦? –

0

如果您所創建的測試套件和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);