【问题标题】:How to create, delete and update Test Steps listed in VSTS Test Cases如何创建、删除和更新 VSTS 测试用例中列出的测试步骤
【发布时间】:2019-09-25 23:26:44
【问题描述】:

我们正在努力构建一种方法,可将测试套件的执行指标自动更新到 VSTS 服务器上。在浏览了 VSTS 的 REST API 文档后,我们能够使用这些自动化 API 执行以下操作

  • 使用所需的现有测试用例列表创建测试运行
  • 更新上面创建的测试运行的测试结果(结果和状态)

现在可以更新测试用例是通过、失败还是任何其他可用结果。但是我们正在寻找一种自动化方法,我们可以通过该方法将每个测试用例中每个测试步骤的状态更新为通过、失败或任何其他可用结果

希望我以更易于理解的方式解释了我们的痛点。

请回复您的建议。

提前致谢。

【问题讨论】:

    标签: rest api azure-devops


    【解决方案1】:

    VSTS 测试用例中列出的测试步骤仍然属于测试结果。

    如果您获得带有参数“detailsToInclude=Iterations”的测试结果,您将看到有“actionResults”来确定测试步骤的结果:

    Get https://xxx.visualstudio.com/TestCase/_apis/test/runs/xx/results/xx?api-version=3.0-preview&detailsToInclude=Iterations
    

    但我尝试使用 REST api Update test results for a test run 更新“actionResults”,发现它不支持更新“actionResults”。 REST API 无法满足您的要求。

    您可以使用本案例中提到的客户端 api,而不是 REST api:How to add/update individual result to each test step in testcase of VSTS/TFS programatically

    简单示例:

    int testpointid = 176;
                var u = new Uri("https://[account].visualstudio.com");
                VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "[pat]"));
                TfsTeamProjectCollection _tfs = new TfsTeamProjectCollection(u, c);
                ITestManagementService test_service = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));
                ITestManagementTeamProject _testproject = test_service.GetTeamProject("scrum2015");
                ITestPlan _plan = _testproject.TestPlans.Find(115);
                ITestRun testRun = _plan.CreateTestRun(false);
                testRun.Title = "apiTest";
                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 (Microsoft.TeamFoundation.TestManagement.Client.ITestStep testStep in result.GetTestCase().Actions)
                    {
                        ITestStepResult stepResult = iterationResult.CreateStepResult(testStep.Id);
                        stepResult.Outcome = Microsoft.TeamFoundation.TestManagement.Client.TestOutcome.Passed; //you can assign different states here
                        iterationResult.Actions.Add(stepResult);
                    }
                    iterationResult.Outcome = Microsoft.TeamFoundation.TestManagement.Client.TestOutcome.Passed;
                    result.Iterations.Add(iterationResult);
                    result.Outcome = Microsoft.TeamFoundation.TestManagement.Client.TestOutcome.Passed;
                    result.State = TestResultState.Completed;
                    result.Save(true);
                }
                testRun.State = Microsoft.TeamFoundation.TestManagement.Client.TestRunState.Completed;
                results.Save(true);
    

    【讨论】:

    • 感谢您的回答,对延迟回复表示抱歉。我可以使用提供的解决方案更新测试步骤状态。有没有这样的方法可以将屏幕截图上传到相应的测试步骤。如果是,请回复。提前致谢
    猜你喜欢
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多