【问题标题】:Retrieve TFS Test Steps always returns count of 0检索 TFS 测试步骤始终返回计数 0
【发布时间】:2018-10-17 08:51:18
【问题描述】:

我正在尝试使用 API (Microsoft.TeamFoundationServer.ExtendedClient v15.112.1) 检索已添加到 TFS (2017.2) 中的测试用例的测试步骤(又名“操作”)。我当前的实现总是返回 0 个测试步骤,尽管实际的测试用例有步骤。我也在一个干净的新团队项目中尝试了这个,没有任何工作项自定义,即使它返回 0 步骤。我的实现使用较旧的 API(基于 SOAP Web 服务),因为似乎较新的基于 http 的 API 尚未实现测试步骤。这是我使用的代码:

private void GetTestStepsForTestCase(int testCaseId, int testSuiteId, 
string teamProjectName, Uri tfsUrl)
{
   TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(tfsUrl);
   ITestManagementService itms = tpc.GetService<ITestManagementService>();
   ITestManagementTeamProject ittp = itms.GetTeamProject(teamProjectName);
   ITestSuiteBase suite = ittp.TestSuites.Find(testSuiteId);
   ITestCaseCollection testCaseCollection = suite.AllTestCases;
   ITestCase itestCase = testCaseCollection.FirstOrDefault(t => t.Id == testCaseId);

   foreach (Microsoft.TeamFoundation.TestManagement.Client.ITestAction itestAction in itestCase.Actions)
   {
      // Do something
   }
}

有人吗?

【问题讨论】:

    标签: c# api tfs tfs-sdk


    【解决方案1】:

    您可以使用以下示例从特定测试套件中检索测试用例步骤,它适用于我:

    安装 nuget 包:Microsoft.TeamFoundationServer.ExtendedClient - 15.112.1

    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.TestManagement.Client;
    using Microsoft.VisualStudio.Services.Client;
    using System;
    
    namespace RetrieveTestSteps
    {
        class Program
        {
            static void Main(string[] args)
            {
                var u = new Uri("http://server:8080/tfs/DefaultCollection");
                var c = new VssClientCredentials();
                TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(u, c);
                tpc.EnsureAuthenticated();   
                ITestManagementService itms = tpc.GetService<ITestManagementService>();
                ITestManagementTeamProject ittp = itms.GetTeamProject("LCScrum");
                ITestSuiteBase suite = ittp.TestSuites.Find(352);
                ITestCaseCollection testCaseCollection = suite.AllTestCases;
    
                foreach (var tc in testCaseCollection)
                {
                    ITestCase testcase = ittp.TestCases.Find(tc.Id);
    
                    foreach (ITestAction action in testcase.Actions)
                    {
                        Console.WriteLine(String.Format("{0} - {1}", testcase.Id, action));
                    }
                }
                Console.Read();
            }
        }
    }
    

    【讨论】:

    • 感谢您的回答安迪。我将代码示例复制到一个新的控制台应用程序(.NET Framework 4.6.1),但我仍然遇到同样的问题。可能与环境有关?
    • @Fokko 你确定你检查了正确的套件或测试用例吗?我建议您创建一个新项目,然后创建一个测试用例以检查问题是否仍然存在。您也可以在另一台机器上尝试该代码。我在不同的机器上进行了测试,它们都按预期工作。
    • @Fokko 您可以尝试使用ITestCase testcase = ittp.TestCases.Find(22); 检查特定测试用例,看看您是否可以检索特定测试用例的测试步骤。
    【解决方案2】:

    好的,我终于自己想出了这个。 Andy 的答案和 cmets 帮助我验证了我的代码是否正确。我刚刚发现我的代码在不调试时运行良好!在调试时,有时我注意到了这一点:

    因此可能是由于某处的延迟加载,无法验证附件调试时间的计数(请参阅此处的帖子:Lazy<T>: "The function evaluation requires all threads to run")。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 2013-04-04
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 1970-01-01
      相关资源
      最近更新 更多