【问题标题】:TFS API and report performance: get test case results by test plan?TFS API 和报告性能:通过测试计划获取测试用例结果?
【发布时间】:2017-11-13 18:00:13
【问题描述】:

在报告中,我需要呈现某个测试计划的所有测试结果。

目前我正在使用以下功能:

foreach (TestCase testCase in testCasesByWorkItem)
{
    List<ITestCaseResult> testCaseResults = teamProject.TestResults.ByTestId(testCase.TestCaseId).Where(x => x.State == TestResultState.Completed).ToList();

    ....

}

我的理解是返回这个测试用例的所有结果,一个测试用例可能属于多个测试计划。

我的问题是性能。该操作最多需要 25 秒(在调试模式下),并且我有数千个测试用例。

我只需要那些属于某个测试计划的测试用例结果。

例如,TestCaseX 可能已针对测试计划 Release1.0、Release2.0、....Release20.0 执行。而且我只对 Release15.0 的结果感兴趣。

目前我如上检索结果,稍后按正确的测试计划过滤。

有没有办法通过某种方式只选择属于给定测试计划的测试结果来优化性能?

【问题讨论】:

  • 我找到了一个提议的建议here。所以我猜它还不支持。

标签: tfs tfs-reports


【解决方案1】:

您可以使用以下示例根据测试计划 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

【讨论】:

    【解决方案2】:

    您可能会发现使用 TFS Rest API 对您正在尝试做的事情很有用。

    https://www.visualstudio.com/en-us/docs/integrate/api/test/runs

    您将能够使用页面上列出的第一个 API 获取给定 planId 的所有测试运行列表,然后使用 runId 使用测试结果 API 获取所有测试返回

    https://www.visualstudio.com/en-us/docs/integrate/api/test/results_1_0

    就我个人而言,我发现使用 API 比使用对象模型要容易得多。

    【讨论】:

      猜你喜欢
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 2015-12-25
      • 2021-11-18
      相关资源
      最近更新 更多