我正在使用Microsoft.TeamFoundation
类在C#中编写控制台应用程序,以连接到Visual Studio Team Foundation Server 2015本地实例。
我的应用程序需要创建/上传测试用例,并将它们链接到现有的用户案例。
如果我使用RelatedLink
类并将其添加到ITestCase.Links
属性中,则当我通过Web门户查看测试用例时,这些链接将显示在所有链接标签下,并且而不是经过测试的用户故事标签。
我该如何链接测试用例和故事,以使它们显示在 Tested User Stories 标签中?
答案 0 :(得分:1)
您需要将链接类型设置为“ Tested By
”。
尝试以下代码示例以将测试用例链接到现有的用户案例 :(安装Nuget软件包Microsoft.TeamFoundationServer.ExtendedClient)
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Linq;
namespace AssociateWorkitems
{
class Program
{
static void Main(string[] args)
{
int UserStoryID = 53;
int TestCaseID = 54;
TfsTeamProjectCollection tfs;
tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://ictfs2015:8080/tfs/DefaultCollection"));
tfs.Authenticate();
var workItemStore = new WorkItemStore(tfs);
WorkItem wit = workItemStore.GetWorkItem(UserStoryID);
//Set "Tested By" as the link type
var linkTypes = workItemStore.WorkItemLinkTypes;
WorkItemLinkType testedBy = linkTypes.FirstOrDefault(lt => lt.ForwardEnd.Name == "Tested By");
WorkItemLinkTypeEnd linkTypeEnd = testedBy.ForwardEnd;
//Add the link as related link.
try
{
wit.Links.Add(new RelatedLink(linkTypeEnd, TestCaseID));
wit.Save();
Console.WriteLine(string.Format("Linked TestCase {0} to UserStory {1}", TestCaseID, UserStoryID));
}
catch (Exception ex)
{
// ignore "duplicate link" errors
if (!ex.Message.StartsWith("TF26181"))
Console.WriteLine("ex: " + ex.Message);
}
Console.ReadLine();
}
}
}