0

We have test cases in VSTS under our project. We are using rest Api to get test case details and trying to update the outcome of test case as pass or fail based on some condition but not able to find the reference field for the outcome. Below is my code:

var collectionUri = "https://microsoft.visualstudio.com/DefaultCollection";

VssBasicCredential _credentials = new VssBasicCredential("", "<PATToken>");

// create workitemtracking client
var _witClient = new WorkItemTrackingHttpClient(new Uri(collectionUri), _credentials);


// get Test Case using all relations
var testCaseObject = _witClient.GetWorkItemAsync(<testcaseid>, null, null, WorkItemExpand.Relations).Result;

In testCaseObject, we are getting all the fields related to testcase but not have any field related to outcome. Please help us here how to update and save the outcome for the test case in VSTS.

Community
  • 1
  • 1

1 Answers1

1

There isn’t outcome field in test case work item, it is used for test point. A test case can have many test points per to configuration.

For your requirement, you can create a new test run with test result to update the outcome of test point.

A simple example:

 var u = new Uri("https://[account].visualstudio.com");
 VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "[pat]"));
 var connection = new VssConnection(u, c);
var testClient = connection.GetClient<TestManagementHttpClient>();
 int testpointid = 158;
 string teamProject = "scrum2015";
RunCreateModel run = new RunCreateModel(name:"APIRun7",plan:new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference("232"),pointIds:new int[] { testpointid });
TestRun testrun = testClient.CreateTestRunAsync(teamProject, run).Result;
TestCaseResultUpdateModel testCaseUpdate = new TestCaseResultUpdateModel() { State="Completed", Outcome="Passed", TestResult=new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference("100000") };
var testResults = testClient.UpdateTestResultsAsync(new TestCaseResultUpdateModel[] { testCaseUpdate }, teamProject, testrun.Id).Result;
RunUpdateModel runmodel = new RunUpdateModel(state: "Completed");
TestRun testRunResult= testClient.UpdateTestRunAsync(teamProject, testrun.Id, runmodel).Result;
starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • I tried above code and getting the error `Error CS1503 Argument 1: cannot convert from 'string' to 'Microsoft.TeamFoundation.TestManagement.WebApi.RunCreateModel' ` for the below line: `TestRun testrun = testClient.CreateTestRunAsync(teamProject, run).Result;` – manish tomar May 12 '17 at 10:18
  • 1
    @manishtomar With 15.0 assemblies, the first parameter type is RunCreateModel, with 14.0 assemblies the first parameter type is string (projectId), so you need to modify your code per to the parameters of CreateTestRunAsync method. On the other hand, this code is just a simple sample, you need to modify it per to your requirements. – starian chen-MSFT May 15 '17 at 01:52
  • I too got error `cannot convert from string to Microsoft.TeamFoundation.TestManagement.WebApi.RunUpdateModel` Does someone has answer for this error. Proper Code correction would be appreciated – Shalem Jun 13 '17 at 07:34
  • @Shalem Check the arguments of UpdateTestRunAsync method. – starian chen-MSFT Jun 13 '17 at 07:48