获取针对测试计划ID执行的所有测试运行详细信息

时间:2015-10-06 01:03:42

标签: tfs tfs2010 tfs-sdk mtm

有没有办法可以针对测试计划ID执行测试运行 以编程方式?另外我想得到过去30天或过去X天的结果?

要获取特定测试运行的测试用例结果,我使用以下查询, var results = proj.TestResults.Query(string.Format("SELECT * FROM TestResult WHERE TestRunId =" + testRunId + ""));

1 个答案:

答案 0 :(得分:2)

针对测试计划ID进行测试运行:

TfsTeamProjectCollection tfctc = new TfsTeamProjectCollection(new Uri("http://tfsservername:8080/tfs/DefaultCollection"));
        ITestManagementService testmanagementService = tfctc.GetService<ITestManagementService>();
        var teamproject = testmanagementService.GetTeamProject("teamprojectname");
        var testruns = testmanagementService.QueryTestRuns("select * From TestRun");
        List<ITestRun> testrunInPlan = new List<ITestRun>(); 
        foreach (var testrun in testruns)
        {
            if (testrun.TestPlanId==31) // in this case TestPlanId is 31
            {
                testrunInPlan.Add(testrun);
            }
        }

获取特定测试运行的测试用例结果:

ITestCaseResultCollection testcases = testrun.QueryResults();

            foreach (ITestCaseResult testcase in testcases)
            {
                Console.WriteLine("TestCase ID: " + testcase.TestCaseId);
                Console.WriteLine("TestCase Title: " + testcase.TestCaseTitle);
                Console.WriteLine("Error Message: " + testcase.ErrorMessage);
            }

请查看此博客,了解有关Test Management API的详细信息:http://blogs.msdn.com/b/aseemb/archive/2012/08/07/code-snippets-on-test-management-apis.aspx