2012-04-19 41 views
2

我正在嘗試使用TestPlan的TFS API獲取特定的TestSuite。使用TFS API通過Id獲取特定的TestSuite

TestSuite可以存在於TestSuite層次結構中的任何位置,所以我當然可以編寫遞歸函數。然而,我想要更高效的東西。

有沒有我缺少的方法,或者我可以寫一個查詢?

回答

5

如果你已經知道testSuiteId事情很簡單。你只需要知道你的TeamProject teamProjectName名稱:

using System; 
using Microsoft.TeamFoundation.Client; 
using Microsoft.TeamFoundation.TestManagement.Client; 

namespace GetTestSuite 
{ 
    class Program 
    { 
     static void Main() 
     { 
      int testSuiteId = 555; 
      const string teamProjectName = "myTeamProjectName"; 

      var tpc = 
       TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
        new Uri("http://tfsURI")); 

      var tstService = (ITestManagementService)tpc.GetService(typeof(ITestManagementService)); 
      var tProject = tstService.GetTeamProject(teamProjectName); 

      var myTestSuite = tProject.TestSuites.Find(testSuiteId);    
     } 
    } 
} 

如果你不這樣做,你可能需要去一個類似的解決方案呈現here(這是一個S.Raiten後),遞歸的確出現在圖片中。假定訪問testPlanId

using System; 
using Microsoft.TeamFoundation.Client; 
using Microsoft.TeamFoundation.TestManagement.Client; 

namespace GetTestSuite 
{ 
    class Program 
    { 
     static void Main() 
     { 
      int testPlanId = 555; 
      const string teamProjectName = "myTeamProjectName"; 

      var tpc = 
       TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
        new Uri("http://tfsURI")); 

      var tstService = (ITestManagementService)tpc.GetService(typeof(ITestManagementService)); 
      var tProject = tstService.GetTeamProject(teamProjectName); 

      var myTestPlan = tProject.TestPlans.Find(testPlanId); 
      GetPlanSuites(myTestPlan.RootSuite.Entries);     
     } 

     public static void GetPlanSuites(ITestSuiteEntryCollection suites) 
     { 
      foreach (ITestSuiteEntry suiteEntry in suites) 
      { 
       Console.WriteLine(suiteEntry.Id); 
       var suite = suiteEntry.TestSuite as IStaticTestSuite; 
       if (suite != null) 
       { 
        if (suite.Entries.Count > 0) 
         GetPlanSuites(suite.Entries); 
       } 
      } 
     } 
    } 
} 
相關問題