简体   繁体   中英

C# TFS API add test cases to Requirement-based suite

I am trying create test cases and add them to existing Requirement-based suite.

below is the code i am trying with but i am able to create test cases but not able to add them 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);

I am facing issues here with IRequirementTestSuite , may be the syntax is different

        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);

how can i add test case to IRequirementTestSuite here

        foundPlan.Save();
    }
}

}

Check this case:

Requirement-based Test Suites are dynamic. The relationship between a Test Case and a Requirement is determined by the presence of a proper Tests/Tested By Work Item Link, so you need to add such a 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();

And the important method:

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM