【问题标题】:Not getting test case results(passed/failed/blocked) from TFS API未从 TFS API 获取测试用例结果(通过/失败/阻止)
【发布时间】:2016-09-28 11:43:19
【问题描述】:

我正在尝试在 tfs api 中获取测试用例的结果

在测试用例管理器中,我看到了以下结果: https://gyazo.com/72ccfcef96d1718907ea702d7a8bbfc9

但是当我尝试在我的测试用例工具中得到这个结果时,我无法得到任何结果:

var testResults = project.TestResults.ByTestId(7987);
foreach (var result in testResults)
{
    var topIteration = result.Iterations.FirstOrDefault();
    if (topIteration == null)
        continue;
    // do something
}

因为 topIteration 总是等于 null。

如何从 tfs api 获得正确的结果(通过/失败/阻止)?

【问题讨论】:

    标签: c# tfs


    【解决方案1】:

    根据您的代码,您似乎想使用 TFS API 检索特定测试用例的测试结果。您可以尝试按照以下步骤来实现您所需要的。

    连接到 TFS 服务器/集合/团队项目

    Uri tfsUri = new Uri("http://servername:8080/tfs/collectionname");
    teamProjectCollection = new TfsTeamProjectCollection(tfsUri);
    
    iTestManagementService = teamProjectCollection.GetService<ITestManagementService>();
    tfsConnectedTeamProject = iTestManagementService.GetTeamProject("Team Project Name");
    

    连接到 TFS 服务器后,调用 API 以获取任何特定测试用例的测试结果。下面的代码行将获取与通过的测试用例 ID 相关的所有结果,并且此返回的列表未排序

    var testResults = tfsConnectedTeamProject.TestResults.ByTestId(7987);
    

    然后你可以使用下面的代码使用ITestCaseResult 的LastUpdated 属性对其进行排序,它会返回你排序的测试结果列表。

    var resSort = from res in testResults
    orderby res.LastUpdated descending
    select res;
    

    如果您只需要结果集合中的最新测试结果,那么下面是代码。使用上面的排序列表并检索最高记录。

    var latestTestResult = resSort.First<ITestCaseResult>();
    

    【讨论】:

      【解决方案2】:

      检查下面的代码:

      TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("url"));
      tfs.EnsureAuthenticated();
      
      IBuildServer tfsBuildServer = tfs.GetService<IBuildServer>();
      
      IBuildDefinition buildDef = tfsBuildServer.GetBuildDefinition("TeamProject", "DefinitionName");
      
       var BuildUri = buildDef.LastBuildUri;
      
       ITestManagementService testManagement = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
       ITestManagementTeamProject testManagementTeamProject = testManagement.GetTeamProject("TeamProject");
       IEnumerable<ITestRun> testRuns = testManagementTeamProject.TestRuns.ByBuild(BuildUri);
      
      
         foreach (ITestRun testRun in testRuns)
           {
             foreach (ITestCaseResult result in testRun.QueryResults())
                {
                  Console.WriteLine(string.Format("TestCaseID:{0}", result.TestCaseTitle.ToString()));
                  Console.WriteLine(string.Format("TestCaseOutcome:{0}", result.Outcome.ToString()));
                 }
            }
      

      【讨论】:

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