代码之家  ›  专栏  ›  技术社区  ›  Fokko

检索TFS测试步骤始终返回0的计数

  •  0
  • Fokko  · 技术社区  · 8 年前

    我正在尝试使用API(Microsoft.TeamFoundationServer.ExtendedClient v15.112.1)检索TFS(2017.2)中添加到测试用例中的测试步骤(也称为“操作”)。我当前的实现总是返回0个测试步骤,尽管实际的测试用例有步骤。我在一个全新的团队项目中也尝试了这一点,没有任何工作项自定义,即使在那里,它也会返回0个步骤。我的实现使用了旧的API(基于SOAP webservices),因为新的基于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
       }
    }
    

    任何人

    2 回复  |  直到 8 年前
        1
  •  0
  •   Andy Li-MSFT    8 年前

    您可以使用下面的示例从特定的测试套件中检索测试用例步骤,它在我这边起作用:

    安装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();
            }
        }
    }
    

    enter image description here

        2
  •  0
  •   Fokko    8 年前

    好吧,我终于自己弄明白了。安迪的回答和评论帮助我验证了我的代码是正确的。我刚刚发现,我的代码在没有调试的情况下运行良好!在调试时,我注意到:

    The function evaluation requires a threads to run

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

    推荐文章