如何从TFS服务器获取测试计划结果

时间:2014-09-24 09:28:27

标签: c# tfs

我创建了一个连接到服务器然后获取测试计划的项目,但是我很难获得测试计划结果(通过,失败和活动测试用例的数量)。 下面的代码是我用来获取测试计划的代码。有关如何获得这些计划的测试结果的任何建议?或者我如何获得单个测试用例的测试运行结果。我可以过滤掉我想要的测试计划,套件和案例,但我无法在任何地方找到结果。

void GetTestPlans(ITestManagementTeamProject testproject)
    {
        ITestPlanCollection plans = testproject.TestPlans.Query("Select * From TestPlan");

        TreeViewItem root = null;
        root = new TreeViewItem();
        root.Header = ImageHelpers.CreateHeader(testproject.WitProject.Name, ItemTypes.TeamProject);
        TreeMain.Items.Add(root);

        foreach (ITestPlan plan in plans)
        {
            if (plan.Name.Contains("C600 Update"))
            {
                TreeViewItem plan_tree = new TreeViewItem();
                string header = plan.Id + "\t" + plan.Name;
                plan_tree.Header = ImageHelpers.CreateHeader(header, ItemTypes.TestPlan);


                if (plan.RootSuite != null && plan.RootSuite.Entries.Count > 0)
                    GetPlanSuites(plan.RootSuite.Entries, plan_tree);

                root.Items.Add(plan_tree);

            }
        }

    }


    void GetPlanSuites(ITestSuiteEntryCollection suites, TreeViewItem tree_item)
    {

        foreach (ITestSuiteEntry suite_entry in suites)
        {
            IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
            if (suite != null)
            {
                TreeViewItem suite_tree = new TreeViewItem();
                suite_tree.Header = ImageHelpers.CreateHeader(suite.Title, ItemTypes.TestSuite);

                GetTestCases(suite, suite_tree);

                tree_item.Items.Add(suite_tree);

                if (suite.Entries.Count > 0)
                    GetPlanSuites(suite.Entries, suite_tree);

            }
        }
    }

    void GetTestCases(IStaticTestSuite suite, TreeViewItem tree_item)
    {
        //AllTestCases - Will show all the Test Cases under that Suite even in sub suites.
        //ITestCaseCollection testcases = suite.AllTestCases;

        //Will bring only the Test Case under a specific Test Suite.
        ITestSuiteEntryCollection suiteentrys = suite.TestCases;

        foreach (ITestSuiteEntry testcase in suiteentrys)
        {
            ITestCase testCase = testcase.TestCase as ITestCase;
            TreeViewItem test = new TreeViewItem();
            string header = testcase.Id + "\t" + testcase.Title;
            test.Header = ImageHelpers.CreateHeader(header, ItemTypes.TestCase);
            tree_item.Items.Add(test);
            GetResults(testCase);
        }
    }


    void GetResults(ITestCase testCase)
    {
        // Would like to get the results for each test case here
        // If there are several test runs, only the latest counts


    }

1 个答案:

答案 0 :(得分:0)

尝试:

testProject.TestResults.ByTestId(testCase.Id);