VSO REST API 中测试用例结果的参考字段



我们的项目下有VSTS中的测试用例。我们正在使用 rest API 来获取测试用例详细信息,并尝试根据某些条件将测试用例的结果更新为passfail,但找不到结果的参考字段。下面是我的代码:

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;

testCaseObject中,我们获得了与测试用例相关的所有字段,但没有任何与结果相关的字段。请在此处帮助我们如何在 VSTS 中更新和保存测试用例的结果。

测试用例工作项中没有结果字段,它用于测试点。每个测试用例可以有多个测试点。

根据您的要求,可以使用测试结果创建新的测试运行,以更新测试点的结果。

一个简单的例子:

 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;

相关内容

  • 没有找到相关文章

最新更新