首页 > 解决方案 > 使用 TFS API 获取测试用例结果/结果

问题描述

如何获取当前的测试用例结果,尤其是那些活跃的,因为我得到了通过。 在此处输入图像描述

标签: tfstfs-sdk

解决方案


您可以首先检索 Active 测试用例是使用 ITestPlan.QueryTestPoints 方法和 TestPointState.Ready 属性。

以下代码片段将列出所有活动测试用例的 Id。请看下面:

ITestManagementService testManagementService = testHelper.GetTestManagementService();
            //Get Team Project
            ITestManagementTeamProject teamProjects= testManagementService.GetTeamProject("TeamProjectName");
 //Get the test plan
            ITestPlan testPlan=teamProjects.TestPlans.Find(int.Parse("3")); //3 is the test plan id on my side
            // Get test points
            ITestPointCollection testPoints= testPlan.QueryTestPoints("SELECT * FROM TestPoint");
            foreach (var item in testPoints)
            {
                if (item.State==TestPointState.Ready)
                {
                    Console.WriteLine(item.TestCaseId);
                }
            }

然后您只需要获取列出的 CaseID 的状态。如果您想获得运行测试步骤的结果,您还可以查看此博客:使用 TFS API 的 MTM 测试记分卡


推荐阅读