C# 如何检索测试用例中的测试步骤数,并以编程方式将单个结果动态更新到VSTS/TFS测试用例中的每个测试步骤

C# 如何检索测试用例中的测试步骤数,并以编程方式将单个结果动态更新到VSTS/TFS测试用例中的每个测试步骤,c#,visual-studio-2015,tfs-2015,azure-devops-rest-api,C#,Visual Studio 2015,Tfs 2015,Azure Devops Rest Api,在VST中,我对每个测试用例都有多个测试步骤。我希望通过编程在一个测试用例中找到测试步骤的数量,并为每个测试步骤动态地手动更新测试结果(通过/失败)以便我可以跟踪在测试用例运行中失败的测试步骤 我找到了更新testcase的teststep结果(通过/失败)的程序。这既不能确定测试用例中测试步骤的数量,也不能单独(通过控制台)动态更新测试步骤结果。测试用例只是另一种工作项类型,步骤只是一个特殊格式的字符串字段(请参阅)。最后,我成功编程了。使用nuget包 您希望如何动态更新teststeps结

在VST中,我对每个测试用例都有多个测试步骤。我希望通过编程在一个测试用例中找到测试步骤的数量,并为每个测试步骤动态地手动更新测试结果(通过/失败)以便我可以跟踪在测试用例运行中失败的测试步骤


我找到了更新testcase的teststep结果(通过/失败)的程序。这既不能确定测试用例中测试步骤的数量,也不能单独(通过控制台)动态更新测试步骤结果。

测试用例只是另一种工作项类型,步骤只是一个特殊格式的字符串字段(请参阅)。

最后,我成功编程了。使用nuget包


您希望如何动态更新teststeps结果?你能提供样品吗?要确定测试用例中的测试步骤数,可以使用result.GetTestCase().Actions.Count。是否有任何编程帮助?
        Console.WriteLine("Please Provide your Test Plan id");
        int testplanid = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Please Provide your testpoint id");
        int testpointid = Convert.ToInt32(Console.ReadLine());

        var u = new Uri("Your account url");
        VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "Your PAT"));
        TfsTeamProjectCollection _tfs = new TfsTeamProjectCollection(u, c);
        ITestManagementService test_service = (ITestManagementService)_tfs.GetService(typeof(ITestManagementService));
        ITestManagementTeamProject _testproject = test_service.GetTeamProject("Your Project name");
        ITestPlan _plan = _testproject.TestPlans.Find(testplanid);
        ITestRun testRun = _plan.CreateTestRun(false);
        testRun.Title = "TestStep Updation Trail1";
        ITestPoint point = _plan.FindTestPoint(testpointid);
        testRun.AddTestPoint(point, test_service.AuthorizedIdentity);
        testRun.Save();
        testRun.Refresh();
        ITestCaseResultCollection results = testRun.QueryResults();
        ITestIterationResult iterationResult;

        foreach (ITestCaseResult result in results)
        {
            iterationResult = result.CreateIteration(1);
            foreach (ITestStep testStep in result.GetTestCase().Actions)
            {
                String TeststepResult;
                ITestStepResult stepResult = iterationResult.CreateStepResult(testStep.Id);
                Console.WriteLine("Enter the TestStep Outcome:");
                TeststepResult= Console.ReadLine();
                if (TeststepResult=="Passed" || TeststepResult=="passed" || TeststepResult=="pass")
                {
                    stepResult.Outcome = TestOutcome.Passed; 
                }
                else
                {
                    stepResult.Outcome = TestOutcome.Failed;
                }
                iterationResult.Actions.Add(stepResult);
            }
            String TestResult;
            Console.WriteLine("Enter the Overall TestCase Result [Passed/Failed] :");
            TestResult= Console.ReadLine();
            if (TestResult == "Passed" || TestResult == "passed" || TestResult=="pass")
            {
                iterationResult.Outcome = TestOutcome.Passed;
                result.Iterations.Add(iterationResult);
                result.Outcome = TestOutcome.Passed;
            }
            else
            {
                iterationResult.Outcome = TestOutcome.Failed;
                result.Iterations.Add(iterationResult);
                result.Outcome = TestOutcome.Failed;
            }
            result.State = TestResultState.Completed;
            result.Save(true);
        }
        testRun.State = TestRunState.Completed;
        results.Save(true);
        Console.WriteLine("Sucesfully Updated TestCase TestSteps");
        Console.Read();