添加测试用例ITestSuiteBase在TFS API [英] Add Test Case to ITestSuiteBase in TFS API
问题描述
我的TFS API工作,并已运行与ITestSuiteBase和IRequirementTestSuite一个问题。我mananged轻松创建IStaticTestSuite中的一个新的测试用例:
I'm working with the TFS API and have run into a problem with ITestSuiteBase and IRequirementTestSuite. I've mananged to easily create a new test case within a IStaticTestSuite:
IStaticTestSuite workingSuite = this.WorkingSuite as IStaticTestSuite;
testCase = CreateTestCase(this.TestProject, tci.Title, tci.Description);
workingSuite.Entries.Add(testCase);
this.Plan.Save();
然而,这种解决方案不要求对测试套件或ITestSuiteBase工作。我会假设会的工作方法是:
However, this solution doesn't work for requirements test suites or ITestSuiteBase. The method that I would assume would work is:
ITestcase testCase = null;
testCase = CreateTestCase(this.TestProject, tci.Title, tci.Description);
this.WorkingSuite.AllTestCases.Add(testCase);
this.WorkingSuite.TestCases.Add(testCase);
this.Plan.Save();
但这种方法实际上并不测试用例添加到套件。它,然而,在测试情况下,添加到该计划。我可以查询创建测试用例但如预期不会在该套件中显示 - 即使立即在代码之后。包括下面刷新工作套房都没有任何好处。
But this method doesn't actually add the test case to the suite. It does, however, add the test case to the plan. I can query the created test case but it doesn't show up in the suite as expected - even immediately in the code afterwards. Refreshing the working suite has no benefit.
附加代码:
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?
Has anyone been able to successfully add a test case to a requirements test suite or a ITestSuiteBase?
推荐答案
朱利奥的链接被证明是做到这一点。
Giulio's link proved to be the best way to do this
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();
}
这篇关于添加测试用例ITestSuiteBase在TFS API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!