在TFS API中将测试用例添加到ITestSuiteBase

我正在使用TFS API并遇到了ITestSuiteBase和IRequirementTestSuite的问题。 我已经马上在IStaticTestSuite中轻松创建一个新的测试用例:

IStaticTestSuite workingSuite = this.WorkingSuite as IStaticTestSuite; testCase = CreateTestCase(this.TestProject, tci.Title, tci.Description); workingSuite.Entries.Add(testCase); this.Plan.Save(); 

但是,此解决方案不适用于需求测试套件或ITestSuiteBase。 我认为可行的方法是:

 ITestcase testCase = null; testCase = CreateTestCase(this.TestProject, tci.Title, tci.Description); this.WorkingSuite.AllTestCases.Add(testCase); this.WorkingSuite.TestCases.Add(testCase); this.Plan.Save(); 

但是这种方法实际上并没有将测试用例添加到套件中。 但是,它确实将测试用例添加到计划中。 我可以查询创建的测试用例,但它不会按预期显示在套件中 – 即使在代码中也会立即显示。 刷新工作套房没有任何好处。

其他代码包括:

  public static ITestCase CreateTestCase(ITestManagementTeamProject project, string title, string desc = "", TeamFoundationIdentity owner = null) { // Create a test case. ITestCase testCase = project.TestCases.Create(); testCase.Owner = owner; testCase.Title = title; testCase.Description = desc; testCase.Save(); return testCase; } 

有没有人能够成功地将测试用例添加到需求测试套件或ITestSuiteBase中?

Giulio的链接被certificate是最好的方法

 testCase = CreateTestCase(this.TestProject, tci.Title, tci.Description); if (this.BaseWorkingSuite is IRequirementTestSuite) TFS_API.AddTestCaseToRequirementSuite(this.BaseWorkingSuite as IRequirementTestSuite, testCase); else if (this.BaseWorkingSuite is IStaticTestSuite) (this.BaseWorkingSuite as IStaticTestSuite).Entries.Add(testCase); this.Plan.Save(); 

而重要的方法是:

 public static void AddTestCaseToRequirementSuite(IRequirementTestSuite reqSuite, ITestCase testCase) { WorkItemStore store = reqSuite.Project.WitProject.Store; WorkItem tfsRequirement = store.GetWorkItem(reqSuite.RequirementId); tfsRequirement.Links.Add(new RelatedLink(store.WorkItemLinkTypes.LinkTypeEnds["Tested By"], testCase.WorkItem.Id)); tfsRequirement.Save(); reqSuite.Repopulate(); } 

这是预料之中的。

静态测试套件是静态的,而基于需求的测试套件是动态的。 测试用例和需求之间的关系由适当的测试/测试工作项链接的存在决定,因此您需要添加这样的链接。

有关示例代码,请参阅无法将测试用例添加到IRequirementTestSuite的类型 。

小注意:您不能复制链接,因此如果测试用例不是新的,您可能需要检查是否存在。