【问题标题】:TFS 2015: adding test steps to test caseTFS 2015:向测试用例添加测试步骤
【发布时间】:2016-11-15 23:23:08
【问题描述】:

我正在尝试以编程方式创建一个测试计划,其中包含一个测试套件和一个测试用例。问题是将测试步骤添加到我的测试用例中。此代码正确地创建了一个测试计划,其中包含一个测试套件和一个测试用例,但在我的测试用例中没有测试步骤。我哪里错了?

   static void Main(string[] args)
    {
        try
        {
            var tfs = TfsHelper.TryToAutenticated();
            var wis = tfs.GetService<WorkItemStore>();


            //TEST PLAN
            // Let's create a new Test Plan from scratch
            // Only the Name property is required to be set before
            // you can save, but we'll set a few extras here as well.
            ITestManagementService service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
            ITestManagementTeamProject myTestManagementTeamProject = service.GetTeamProject("GammaEnterprise");
            ITestPlan newTestPlan = myTestManagementTeamProject.TestPlans.Create();
            newTestPlan.Name = "My Test Plan";                
            newTestPlan.Save();


            //TEST SUITE
            // Next let's add a new Test Suite to our plan
            // First, create a static suite (I'll cover Dynamic Suites
            // in a future post)
            IStaticTestSuite newSuite = myTestManagementTeamProject.TestSuites.CreateStatic();
            newSuite.Title = "My Suite";

            newTestPlan.RootSuite.Entries.Add(newSuite);
            newTestPlan.Save();


            //TEST CASE
            // Let's find the default configuration that was created when
            // we created our Team Project.  We'll need this to add some
            // tests to our new suite (or we could create a new one, but 
            // I'll keep things simple and just get the default one for now)
            ITestConfiguration defaultConfig = null;

            foreach (ITestConfiguration config in myTestManagementTeamProject.TestConfigurations.Query(
                "Select * from TestConfiguration"))
            {
                defaultConfig = config;
                break;
            }

            // I would typically check that defaultConfig is not null here
            // but for brevity sake will skip that.

            // Next we'll create a Testcase to add to our Test Suite
            ITestCase tc = myTestManagementTeamProject.TestCases.Create();
            tc.Title = "Verify X";             


            //HERE THE PROBLEM----------------------
            ITestStep ts = tc.CreateTestStep();
            ts.TestStepType = TestStepType.ActionStep;
            ts.Description = "Description";
            ts.Title = "Title";
            //---------------------------------------
            tc.Save();

            // Now let's add it to your suite, we still have our reference
            // to the static suite around so we'll use that
            // First we need an "IdAndName" object for our config
            IdAndName defaultConfigIdAndName = new IdAndName(defaultConfig.Id, defaultConfig.Name);

            // Now we'll set the default configs for our suite
            newSuite.SetDefaultConfigurations(new IdAndName[] { defaultConfigIdAndName } );

            // Now let's add that testcase
            newSuite.Entries.Add(tc);

            // Now let's save the plan (don't need to explicitly
            // save test suites).
            newTestPlan.Save();
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.ReadLine();
        }
    } 

【问题讨论】:

    标签: c# tfs


    【解决方案1】:

    您可以使用命名空间:Microsoft.TeamFoundation.TestManagement.Client

    例如:

       var step = testCase.CreateTestStep();
       step.Title = "Step 1 @param1";
       step.ExpectedResult = "Expect 1 @param2";
       testCase.Actions.Add(step);
       testCase.Save();
    

    所以我认为您只需要在操作中添加步骤。

    更多细节:

    https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.testmanagement.client.itestbase.actions.aspx

    【讨论】:

    • @LucaF。如果有效,您可以将其标记为答案。这将有助于人们以后浏览该网站。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-12
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    相关资源
    最近更新 更多