Add Test Result to a test run(testcase) in VSTS

后端 未结 2 1938
鱼传尺愫
鱼传尺愫 2021-01-22 00:15

I need to add test result to a testcase in VSTS. I\'m new to VSTS and not sure what went wrong with my code

var ur = new Uri("https://{myaccount}.visualstudi         


        
2条回答
  •  甜味超标
    2021-01-22 00:36

            try
            {
                var u = new Uri("https://{My 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();
                int testpointid = 1;
                string teamProject = "MyProjectName";
                RunCreateModel run = new RunCreateModel(name: "TestCase Name", plan: new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference("TestPlan Id"), pointIds: new int[] { testpointid });
                TestRun testrun = testClient.CreateTestRunAsync(run, teamProject).Result;
    
                TestCaseResult caseResult = new TestCaseResult() { State = "Completed", Outcome = "passed", Id = 100000 };
    
                var testResults = testClient.UpdateTestResultsAsync(new TestCaseResult[] { caseResult }, teamProject, testrun.Id).Result;
                RunUpdateModel runmodel = new RunUpdateModel(state: "Completed");
                TestRun testRunResult = testClient.UpdateTestRunAsync(runmodel, teamProject, testrun.Id, runmodel).Result;
    
            }
            catch (AggregateException e)
            {
                Console.WriteLine(e.InnerException.Message);
    
            }
    

    Note: Instructions to configure

    1. Install Microsoft Team Foundation Server Extended Client package

    Install-Package Microsoft.TeamFoundationServer.ExtendedClient -Version 15.112.1

    1. Install Test Manager extension, Create test plan, test suite in Test tab

    2. testpointid is TestCase number (i.e. order/index of testcase in test plan) and not the ID of the TestCase

    3. name is Testcase name, testrun.Id is auto-captured through testpointid (first index being 1)

提交回复
热议问题