2016-03-08 26 views
0

我想使用C#訪問TFS項目並創建一個測試用例。下面是項目結構C#在項目組中添加測試用例或用戶故事

網址:http://localhost:8080/tfs/test

項目:PROJECT1

球隊名稱:TEAM1

添加測試用例或在這裏工作項目

我是能夠連接到項目並在那裏添加工作項目,但是如何c在我連接到一個特定的團隊項目(在這種情況下,它是TEAM1),並添加測試用例或工作項

這裏是我的示例代碼

namespace ConsoleApplication1 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     Uri collectionUri = (args.Length < 1) ? 
        new Uri("http://localhost:8080/tfs/test") : new Uri(args[0]); 
     System.Console.WriteLine(collectionUri); 
     TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri); 
     WorkItemStore workItemStore = tpc.GetService<WorkItemStore>(); 
     Project teamProject = workItemStore.Projects["project1"]; 
     WorkItemType workItemType = teamProject.WorkItemTypes["User Story"]; 


     // Create the work item. 
     WorkItem userStory = new WorkItem(workItemType) 
     { 
      // The title is generally the only required field that doesn’t have a default value. 
      // You must set it, or you can’t save the work item. If you’re working with another 
      // type of work item, there may be other fields that you’ll have to set. 
      Title = "test through code", 
      Description = 
       "this is an automation user story genrated" 
     }; 

     // Save the new user story. 
     userStory.Save(); 
    } 
} 
} 

回答

0

我們使用的分類字段(區域和迭代)在TFS中定義「團隊」。您沒有指定您如何定義「團隊」,但假設您使用分類字段,則可以如下設置迭代字段:

WorkItem userStory = new WorkItem(workItemType) 
    { 
     // The title is generally the only required field that doesn’t have a default value. 
     // You must set it, or you can’t save the work item. If you’re working with another 
     // type of work item, there may be other fields that you’ll have to set. 
     Title = "test through code", 
     Description = 
      "this is an automation user story genrated", 
     IterationPath = FormatPath(commonservice.GetNode(newIterationPath).Path, "Iteration", "MyTeamProject"); 
    }; 
相關問題