我有API鏈接,這個任務VSTS如何測試結果添加到測試運行使用REST API編程
POST https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/results?api-version={version}
https://www.visualstudio.com/en-us/docs/integrate/api/test/results#add-test-results-to-a-test-run
我需要的程序做通過API方式。
另類,我試過用程序如下
public void GetResult() { var u = new Uri("https://{UserAccount}.visualstudio.com"); VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "MyPAT")); var connection = new VssConnection(u, c); var testClient = connection.GetClient<TestManagementHttpClient>(); int testpointid = 100; string teamProject = "Project12345"; RunCreateModel run = new RunCreateModel(name: "APIRun7", plan: new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference("100"), pointIds: new int[] { testpointid }); TestRun testrun = testClient.CreateTestRunAsync(run, teamProject).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(runmodel ,teamProject, testrun.Id, runmodel).Result; }
我得到了錯誤: 無法從 'Microsoft.TeamFoundation.TestManagement.WebApi.TestCaseResultUpdateModel []' 到「Microsoft.TeamFoundation轉換.TestManagement.WebApi.TestCaseResult []」
我的計劃力鍛鍊......所以只能在這裏發帖求助 – Shalem
你是使用15.0包,所以改變代碼是這樣的:TestCaseResult caseResult = new TestCaseResult(){State =「Completed」,Outcome =「passed」,Id = 100000}; var testResults = testClient.UpdateTestResultsAsync(new TestCaseResult [] {caseResult},teamProject,testrun.Id).Result; –
Remove TestCaseResultUpdateModel testCaseUpdate = new TestCaseResultUpdateModel(){State =「Completed」,Outcome =「Passed」,TestResult = new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference(「100000」)}; –