Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
675 views
in Technique[技术] by (71.8m points)

c# - How to add/update individual result to each test step in testcase of VSTS/TFS programatically

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The simple way is using client API:

Simple sample:

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

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...