0

在我们的项目下,我们在 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 中更新和保存测试用例的结果。

4

1 回答 1

1

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

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

一个简单的例子:

 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;
于 2017-05-12T04:56:00.827 回答