C# TFS API 将测试用例添加到基于需求的套件中
C# TFS API add test cases to Requirement-based suite
我正在尝试创建测试用例并将它们添加到现有的基于需求的套件中。
下面是我正在尝试使用的代码,但我能够创建测试用例,但无法将它们添加到基于需求的套件中
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Uri tfsUri = new Uri("http://tfsint:8080/tfs/sandbox/");
string teamProjectName = "Scrum Custom";
TfsTeamProjectCollection Tfs = new TfsTeamProjectCollection(tfsUri);
ITestManagementService service = (ITestManagementService)Tfs.GetService(typeof(ITestManagementService));
ITestManagementTeamProject TestProject = (ITestManagementTeamProject)service.GetTeamProject(teamProjectName);
//ITestPlanCollection testPlanCollection = TestProject.TestPlans.Query("SELECT * FROM TestPlan");
int myPlansId = 2009;
ITestPlan foundPlan = TestProject.TestPlans.Find(myPlansId);
Console.WriteLine("Got Plan {0} with Id {1}",
foundPlan.Name, foundPlan.Id);
//ITestSuiteBase newSuite = TestProject.TestSuites.Find(myTestSuiteId);
我在这里遇到 IRequirementTestSuite 的问题,可能是语法不同
int myTestSuiteId = 2037;
IRequirementTestSuite newSuite = TestProject.TestSuites.Find(myTestSuiteId);
ITestConfiguration defaultConfig = null;
foreach (ITestConfiguration config in TestProject.TestConfigurations.Query(
"Select * from TestConfiguration"))
{
defaultConfig = config;
break;
}
ITestCase tc = TestProject.TestCases.Create();
tc.Title = "SAF test";
tc.Area = "Scrum Custom\Selenium Integration POC";
//tc.Links.Add
tc.Save();
System.Windows.Forms.MessageBox.Show("test case id = " + tc.Id);
IdAndName defaultConfigIdAndName = new IdAndName(
defaultConfig.Id, defaultConfig.Name);
如何在此处向 IRequirementTestSuite 添加测试用例
foundPlan.Save();
}
}
}
检查this个案:
基于需求的测试套件是动态的。测试用例和需求之间的关系由适当的 Tests/Tested By Work Item Link 的存在决定,因此您需要添加这样的 link.
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();
}
我正在尝试创建测试用例并将它们添加到现有的基于需求的套件中。
下面是我正在尝试使用的代码,但我能够创建测试用例,但无法将它们添加到基于需求的套件中
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Uri tfsUri = new Uri("http://tfsint:8080/tfs/sandbox/");
string teamProjectName = "Scrum Custom";
TfsTeamProjectCollection Tfs = new TfsTeamProjectCollection(tfsUri);
ITestManagementService service = (ITestManagementService)Tfs.GetService(typeof(ITestManagementService));
ITestManagementTeamProject TestProject = (ITestManagementTeamProject)service.GetTeamProject(teamProjectName);
//ITestPlanCollection testPlanCollection = TestProject.TestPlans.Query("SELECT * FROM TestPlan");
int myPlansId = 2009;
ITestPlan foundPlan = TestProject.TestPlans.Find(myPlansId);
Console.WriteLine("Got Plan {0} with Id {1}",
foundPlan.Name, foundPlan.Id);
//ITestSuiteBase newSuite = TestProject.TestSuites.Find(myTestSuiteId);
我在这里遇到 IRequirementTestSuite 的问题,可能是语法不同
int myTestSuiteId = 2037;
IRequirementTestSuite newSuite = TestProject.TestSuites.Find(myTestSuiteId);
ITestConfiguration defaultConfig = null;
foreach (ITestConfiguration config in TestProject.TestConfigurations.Query(
"Select * from TestConfiguration"))
{
defaultConfig = config;
break;
}
ITestCase tc = TestProject.TestCases.Create();
tc.Title = "SAF test";
tc.Area = "Scrum Custom\Selenium Integration POC";
//tc.Links.Add
tc.Save();
System.Windows.Forms.MessageBox.Show("test case id = " + tc.Id);
IdAndName defaultConfigIdAndName = new IdAndName(
defaultConfig.Id, defaultConfig.Name);
如何在此处向 IRequirementTestSuite 添加测试用例
foundPlan.Save();
}
}
}
检查this个案:
基于需求的测试套件是动态的。测试用例和需求之间的关系由适当的 Tests/Tested By Work Item Link 的存在决定,因此您需要添加这样的 link.
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();
}