首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何为测试套件中的特定测试用例更新TFS中的测试结果。不应在C#中的某个套件中将所有测试用例标记为进行中

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

Stack Overflow用户
提问于 2019-09-28 14:39:41
回答 1查看 583关注 0票数 1

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

它会更新测试套件中测试用例的结果,但也会使位于测试套件中的其余测试用例处于进行中状态。

代码语言:javascript
运行
复制
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上进行结果更新,并且测试套件中的其余测试用例状态不应更改。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-30 10:10:24

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

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

代码语言:javascript
运行
复制
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();

        }

更多细节请看这里的类似问题:Changing the outcome field of testcases within a test suite in Tfs

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58143996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档