Changing the outcome field of testcases within a t

2019-09-20 08:43发布

问题:

Given a Test Suite id, is it possible to change the outcome of the test cases within it in Tfs ?

For instance , changing the active state to pass state or to failed state.

While iterating through the test cases with a test suite, i couldnt find a field by the name outcome. How can we modify the outcome field?

回答1:

Seems you want to update the test result. You need to get the test run ID first.

You can use the REST API to update the specific test result. Please see Update test results for a test run for details.

PATCH https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/results?api-version={version}

You can also use TFS API, for example:

TfsTeamProjectCollection teamCollection;
            ITestManagementService service;
            ITestManagementTeamProject project;
            var picker = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
            picker.ShowDialog();
            if (picker.SelectedTeamProjectCollection != null && picker.SelectedProjects != null)
            {
                teamCollection = picker.SelectedTeamProjectCollection;
                service = teamCollection.GetService<ITestManagementService>();
                project = service.GetTeamProject(picker.SelectedProjects.First().Name);
            }
            else
            {
                return;
            }

//Get Test result
 var testResults = project.TestResults.ByTestId([test case id]);

 // iterate each result for the case
 foreach (ITestCaseResult result in testResults)
 {
     //TODO other code
     //update result
     result.Outcome = TestOutcome.Failed;
     result.Save(true);
}

Reference this thread : How to update the test case result in MTM using C#