如何以编程方式在VSTS/TFS的测试用例中的每个测试步骤中添加/更新单个结果 [英] How to add/update individual result to each test step in testcase of VSTS/TFS programatically

查看:141
本文介绍了如何以编程方式在VSTS/TFS的测试用例中的每个测试步骤中添加/更新单个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够通过程序将测试结果更新为VSTS中的测试用例. 测试用例结果更新

I'm able to update test result to testcase in VSTS through program. Test Case Result Updation

现在,我想更新测试用例中每个测试步骤的结果.找不到任何相关信息.请帮助

Now, i want to update the result of each test step in test case. Couldn't find any related info. Please help

推荐答案

简单的方法是使用客户端API:

The simple way is using client API:

简单示例:

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

关于REST api,必要的信息存储在 iterationDetails (TestCaseResult.IterationDetails)的 actionResults 中,您可以尝试将 IterationDetails 指定为 TestCaseResult 并更新测试结果.

Regarding REST api, the necessary information is stored in actionResults of iterationDetails (TestCaseResult.IterationDetails), you can try specify IterationDetails to TestCaseResult and update test result.

您可以使用

You can check the details of a test result by using Get a Test Result with DetailInclude (detailsToInclude=Iterations)

这篇关于如何以编程方式在VSTS/TFS的测试用例中的每个测试步骤中添加/更新单个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆