如何创建,删除和更新VSTS测试用例中列出的测试步骤

时间:2018-04-10 05:02:09

标签: rest api azure-devops

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

执行以下操作
  • 使用所需的现有测试用例列表创建测试RUN
  • 更新上述创建的测试运行的测试结果(结果和状态)

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

希望我能以更容易理解的方式解释我们的痛苦方面。

请回复你的建议。

提前致谢。

1 个答案:

答案 0 :(得分:0)

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);