未使用TFS API从TestSuite获取测试用例结果(传递/失败/阻止)

时间:2013-05-03 07:12:10

标签: c# tfs tfs2010 tfs2012 microsoft-test-manager

我试图在测试计划下从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;
    }

我没有通过测试/失败/未完成测试计数的正确结果。 当我调试到这个时,观察到一些属性显示消息“功能评估已禁用,因为先前的功能评估已超时。您必须继续执行以重新启用功能评估。” 我可以获得测试套件下传递的测试用例数量吗? 这可能是什么问题?

0 个答案:

没有答案