1

我正在尝试根据测试计划从 TestSuite 获取测试用例结果(通过/失败/阻止)。

使用下面的代码来做到这一点。

  public List<ScoreBoard> GetTestStatistics(string teamProject, string selectedTestPlan)
    {
        // 1. Connect to TFS and Get Test Managemenet Service and Get all Test Plans
        string serverName = "*********";
        var server = new Uri(serverName);
        var tfs = TfsTeamProjectCollectionFactory
        .GetTeamProjectCollection(server);
        var service = tfs.GetService<ITestManagementService>();
        var testProject = service.GetTeamProject(teamProject);
        var plan = testProject.TestPlans.Query("SELECT * FROM TestPlan").Where(tp => tp.Name == selectedTestPlan).FirstOrDefault();
        List<ScoreBoard> scoreboards = new List<ScoreBoard>();
        var testSuits = new List<IStaticTestSuite>();
        if (plan.RootSuite != null)
        {
            testSuits.AddRange(TestSuiteHelper.GetTestSuiteRecursive(plan.RootSuite));
        }
        TestPlan testPlan = new TestPlan() { Id = plan.Id, Name = plan.Name, TestSuites = testSuits };

        for (int i = 0; i < testPlan.TestSuites.Count; i++)
        {
            var ts = testPlan.TestSuites[i];
            var scoreboard = new ScoreBoard();
            scoreboard.TeamProject = teamProject;
            scoreboard.TestPlan = selectedTestPlan;
            scoreboard.Id = ts.Id;
            scoreboard.Title = ts.Title;
            scoreboard.State = ts.State.ToString();
            scoreboard.TestCaseCount = ts.TestCases.Count;

              int totalTestSteps = 0;
            List<string> testStepScores = new List<string>();
            foreach (var tc in ts.TestCases)
            {
                foreach (var a in tc.TestCase.Actions)
                {
                    totalTestSteps = totalTestSteps + 1;
                }                

                var testResults = testProject.TestResults.ByTestId(tc.TestCase.TestSuiteEntry.Id);
                foreach (var result in testResults)
                {


                    for (int actionIndex = 0; actionIndex < tc.TestCase.Actions.Count; actionIndex++)
                    {
                        var action = tc.TestCase.Actions[actionIndex];
                        if (!(action is ITestStep))
                        {
                            continue;
                        }
                        var step = action as ITestStep;
                        var topIteration = result.Iterations.FirstOrDefault();
                        if (topIteration == null)
                            continue;

                        var test = topIteration.Actions[actionIndex];
                        testStepScores.Add(topIteration.Actions[actionIndex].Outcome.ToString());
                    }
                }
            }
              scoreboard.TestStepCount = totalTestSteps;
            scoreboard.TestStepPassedCount = testStepScores.Where(tsp => tsp == "Passed").ToList().Count;
            scoreboard.TestStepFailedCount = testStepScores.Where(tsp => tsp == "Failed").ToList().Count;
            scoreboard.TestStepOutstandingCount = testStepScores.Where(tsp => tsp == "None").ToList().Count;
            scoreboards.Add(scoreboard);
        }
        return scoreboards;
    }

我没有得到通过测试/失败/优秀测试计数的正确结果。当我对此进行调试时,观察到某些属性显示消息“函数评估已禁用,因为先前的函数评估超时。您必须继续执行才能重新启用函数评估。” 我可以得到在测试套件下通过了多少测试用例吗?这里可能是什么问题?

4

0 回答 0