如何使用api在Microsoft测试管理器中的另一个套件内创建一个套件

时间:2016-06-29 17:59:35

标签: c# api tfs mtm

这是第一步

IStaticTestSuite testSuite = _teamProject.TestSuites.CreateStatic();
// create an empty test suite below
IStaticTestSuite mtmTestSuite = _teamProject.TestSuites.CreateStatic(); 

我想在mtmTestSuite内添加testsuite,因为我们可以手动执行此操作。

2 个答案:

答案 0 :(得分:0)

尝试使用以下代码:

ITestPlanCollection plans = testproject.TestPlans.Query("Select * From TestPlan");
            var p = plans.Where(pp => pp.Name == "Plan1").First();
            IStaticTestSuite newSuite = testproject.TestSuites.CreateStatic();
            newSuite.Title = "Acceptance Tests";
            IStaticTestSuite pSuite = p.RootSuite.Entries.Where(s => s.Title == "WindowsFormDemoTest").First().TestSuite as IStaticTestSuite;
            pSuite.Entries.Add(newSuite);
           // p.RootSuite.Entries.Add(newSuite);
            p.Save();

您可以通过更多方式参考'添加新TFS测试套件'来自此链接:http://gitkraken.com/

答案 1 :(得分:0)

如果您同时创建testSuite和mtmTestSuite,则只需添加一行代码即可在创建testSuite并将其添加到测试计划/套件后将mtmTestSuite添加到testSuite中:

testSuite.Entries.Add(mtmTestSuite);

如果testSuite已经存在,那么您需要首先获取testSuite,然后将mtmTestSuite添加到其中。例如:

    IStaticTestSuite testSuite = itmtp.TestSuites.CreateStatic();
    foreach (IStaticTestSuite ts in itmtp.TestSuites.Query("Select * From TestSuite"))
    {
        if (ts.Id == 103)//Get the test suite by ID
        {
            testSuite = ts;
        }
    }
    IStaticTestSuite mtmTestSuite = itmtp.TestSuites.CreateStatic();
    mtmTestSuite.Title = "Title";
    testSuite.Entries.Add(mtmTestSuite);