【问题标题】:How to retrieve no.of teststeps in a test case and dynamically update individual result to each test step in testcase of VSTS/TFS programatically如何检索测试用例中的测试步骤数量并以编程方式将单个结果动态更新到 VSTS/TFS 测试用例中的每个测试步骤
【发布时间】:2017-12-01 14:39:05
【问题描述】:

我对 VSTS 中的每个测试用例都有多个测试步骤。我想以编程方式在测试用例中找到测试步骤的数量,并为每个测试步骤手动更新测试结果(通过/失败)。 这样我就可以追踪在测试用例运行中哪个测试步骤失败了

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

【问题讨论】:

  • 您希望如何动态更新测试步骤结果?你能提供一个样品吗?确定没有。测试用例中的测试步骤,您可以 result.GetTestCase().Actions.Count.

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


【解决方案1】:

终于,我编程成功了。使用nuget包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();

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 您有任何编程帮助吗?
    猜你喜欢
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多