如何为测试套件中的特定测试用例更新 TFS 中的测试结果。在 C# 的套件中,不应将所有测试用例标记为进行中

How to Updating test results in TFS for a specific test case in test suite. All Test Cases should not be marked as In Progress in a Suite in C#

我在执行测试用例后使用 API 在 tfs 中使用 udpdate tescase 结果的方法,但它使所有其他测试用例在测试套件中处于进行中状态。

它更新测试套件中测试用例的结果,但它也使位于测试套件中的测试用例的其余部分保持在进行中。

ITestCaseResult result = run.QueryResults().FirstOrDefault(r => r.TestCaseId == testCase.Id);
if (result != null)
{

    testRun.Title = testCase.Title;
    result.ComputerName = Environment.MachineName;
    result.Outcome = TestOutcome.Passed;
    result.Comment = comments;
    result.RunBy = testRun.Owner;
    result.State = TestResultState.Completed;
    result.Save();
}

我预计,应该对我在 运行 时通过的特定测试用例 ID 进行结果更新,并且测试套件中剩余的测试用例状态不应更改。

没有完整的代码,不确定哪一部分是根本原因,但可能与if (result != null)有关,条件语句会影响结果。

请尝试使用以下代码示例来处理此问题。

publicstaticvoidUpdateResult()
        {

            TfsTeamProjectCollectiontfs = newTfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(server));
            ITestManagementServicetms = tfs.GetService<ITestManagementService>();
            ITestManagementTeamProjectproj = tms.GetTeamProject(project);
            ITestPlanPlan = proj.TestPlans.Find(1);
IStaticTestSuitesuite = Plan.RootSuite.SubSuites.Where(s => s.Id == 1339).First() asIStaticTestSuite;
            ITestCasetestcase = null;
            testcase = suite.Entries.Where(e => e.Title == "login").First().TestCase;
            ITestRuntestRun = project.TestRuns.Create();
            testRun = Plan.CreateTestRun(false); 

            ITestPointCollectionpoints = Plan.QueryTestPoints("SELECT * FROM TestPoint WHERE TestCaseId ="+ testcase.Id);
            foreach(ITestPointp inpoints)
            {

                testRun.AddTestPoint(p, Plan.Owner);// null);
                //testRun.AddTestPoint(p, null);

            }
            testRun.State = TestRunState.Completed;
            testRun.Save();

            ITestCaseResultCollectionresults = testRun.QueryResults();
            ITestIterationResultiterationResult;
            foreach(ITestCaseResultresult inresults)
            {
                iterationResult = result.CreateIteration(1);
                foreach(ITestSteptestStep inresult.GetTestCase().Actions)
                {
                    ITestStepResultstepResult = iterationResult.CreateStepResult(testStep.Id);
                    stepResult.Outcome = TestOutcome.Passed;                        
                    iterationResult.Actions.Add(stepResult);

                }
                iterationResult.Outcome = TestOutcome.Passed;
                result.Iterations.Add(iterationResult);
                result.Outcome = TestOutcome.Passed;
                result.State = TestResultState.Completed;
                result.Save(true);

            }
            testRun.Save();
            testRun.Refresh();

        }

更多详细信息请查看此处的类似问题: