1

有没有办法让我以编程方式针对测试计划 id 执行测试运行?我也想得到最后 30 天或最后 X 天的结果?

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

4

1 回答 1

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);
            }

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

于 2015-10-06T07:39:38.807 回答