C#在项目中的团队下添加测试用例或用户故事

时间:2016-03-08 15:36:53

标签: tfs tfsbuild tfs2013 azure-devops team-explorer

我想使用C#访问TFS项目并创建一个测试用例。以下是项目结构

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

项目:project1

团队名称:team1

在此处添加测试用例或工作项

我可以连接到项目并在那里添加工作项,但是我如何连接到项目中的特定团队(在这种情况下是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();
    }
}
}

1 个答案:

答案 0 :(得分:0)

我们使用Classification字段(Area和Iteration)在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");
    };