如何在测试用例中检索no.of测试步骤,并以编程方式动态更新单个结果到VSTS / TFS测试用例中的每个测试步骤

时间:2017-06-28 09:42:01

标签: c# visual-studio-2015 tfs2015 azure-devops-rest-api

我在VSTS中为每个测试用例提供了多个测试步骤。我想以编程方式在测试用例中找到no.of测试步骤,并动态地为每个测试步骤手动更新测试结果(Pass / Fail)。 这样我就可以在测试用例运行中跟踪哪些测试步骤失败

我找到了更新testcase的测试步骤结果(通过/失败)的TestSteps result updation程序。这不能确定测试用例中的测试步骤数,也不能单独动态更新测试步骤结果(通过控制台)

2 个答案:

答案 0 :(得分:1)

最后,我已成功编程。使用nuget Package Microsoft Team Foundation Server Extended Client

        Console.WriteLine("Please Provide your Test Plan id");
        int testplanid = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Please Provide your testpoint id");
        int testpointid = Convert.ToInt32(Console.ReadLine());

        var u = new Uri("Your account url");
        VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "Your PAT"));
        TfsTeamProjectCollection _tfs = new TfsTeamProjectCollection(u, c);
        ITestManagementService test_service = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));
        ITestManagementTeamProject _testproject = test_service.GetTeamProject("Your Project name");
        ITestPlan _plan = _testproject.TestPlans.Find(testplanid);
        ITestRun testRun = _plan.CreateTestRun(false);
        testRun.Title = "TestStep Updation Trail1";
        ITestPoint point = _plan.FindTestPoint(testpointid);
        testRun.AddTestPoint(point, test_service.AuthorizedIdentity);
        testRun.Save();
        testRun.Refresh();
        ITestCaseResultCollection results = testRun.QueryResults();
        ITestIterationResult iterationResult;

        foreach (ITestCaseResult result in results)
        {
            iterationResult = result.CreateIteration(1);
            foreach (ITestStep testStep in result.GetTestCase().Actions)
            {
                String TeststepResult;
                ITestStepResult stepResult = iterationResult.CreateStepResult(testStep.Id);
                Console.WriteLine("Enter the TestStep Outcome:");
                TeststepResult= Console.ReadLine();
                if (TeststepResult=="Passed" || TeststepResult=="passed" || TeststepResult=="pass")
                {
                    stepResult.Outcome = TestOutcome.Passed; 
                }
                else
                {
                    stepResult.Outcome = TestOutcome.Failed;
                }
                iterationResult.Actions.Add(stepResult);
            }
            String TestResult;
            Console.WriteLine("Enter the Overall TestCase Result [Passed/Failed] :");
            TestResult= Console.ReadLine();
            if (TestResult == "Passed" || TestResult == "passed" || TestResult=="pass")
            {
                iterationResult.Outcome = TestOutcome.Passed;
                result.Iterations.Add(iterationResult);
                result.Outcome = TestOutcome.Passed;
            }
            else
            {
                iterationResult.Outcome = TestOutcome.Failed;
                result.Iterations.Add(iterationResult);
                result.Outcome = TestOutcome.Failed;
            }
            result.State = TestResultState.Completed;
            result.Save(true);
        }
        testRun.State = TestRunState.Completed;
        results.Save(true);
        Console.WriteLine("Sucesfully Updated TestCase TestSteps");
        Console.Read();

答案 1 :(得分:0)

测试用例只是另一种工作项类型,步骤只是一个特殊格式的字符串字段(参见https://www.visualstudio.com/en-us/docs/work/track/build-test-integration#build-and-test-data-fields)。