首页 文章

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

提问于
浏览
0

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

  • 使用所需的现有测试用例列表创建测试RUN

  • 更新上述创建的测试运行的测试结果(结果和状态)

现在可以更新测试用例是通过,失败还是任何其他可用结果 . 但 we are looking for an automated approach with which we can update the status of each Test Step inside each Test Case to Pass, Fail or any other available outcomes .

希望我能用更容易理解的方式解释我们的疼痛区域 .

请回复你的建议 .

提前致谢 .

1 回答

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

相关问题