Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检索TFS测试步骤始终返回0的计数_C#_Api_Tfs_Tfs Sdk - Fatal编程技术网

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

C# 检索TFS测试步骤始终返回0的计数,c#,api,tfs,tfs-sdk,C#,Api,Tfs,Tfs Sdk,我正在尝试使用API(Microsoft.TeamFoundationServer.ExtendedClient v15.112.1)检索TFS(2017.2)中添加到测试用例中的测试步骤(也称为“操作”)。我当前的实现总是返回0个测试步骤,尽管实际的测试用例有步骤。我在一个全新的团队项目中也尝试过这个方法,没有任何工作项定制,即使在那里它也返回0个步骤。我的实现使用了旧的API(基于SOAP Web服务),因为新的基于http的API似乎还没有实现测试步骤。这是我使用的代码: private

我正在尝试使用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
   }
}
private void GetTestStepsForTestCase(int-testCaseId,int-testSuiteId,
字符串teamProjectName,Uri tfsUrl)
{
TfsTeamProjectCollection tpc=新的TfsTeamProjectCollection(tfsUrl);
ITestManagementService itms=tpc.GetService();
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.iTestation itestCase.Actions中的iTestation)
{
//做点什么
}
}

有人吗?

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

安装nuget软件包:

使用Microsoft.TeamFoundation.Client;
使用Microsoft.TeamFoundation.TestManagement.Client;
使用Microsoft.VisualStudio.Services.Client;
使用制度;
命名空间检索测试步骤
{
班级计划
{
静态void Main(字符串[]参数)
{
var u=新Uri(“http://server:8080/tfs/DefaultCollection");
var c=新的VssClientCredentials();
TfsTeamProjectCollection tpc=新的TfsTeamProjectCollection(u,c);
tpc.确保重新验证();
ITestManagementService itms=tpc.GetService();
ITestManagementTeamProject ittp=itms.GetTeamProject(“LCScrum”);
ITestSuiteBase suite=ittp.TestSuites.Find(352);
ITestCaseCollection testCaseCollection=suite.AllTestCases;
foreach(testCaseCollection中的var tc)
{
ITestCase testcase=ittp.TestCases.Find(tc.Id);
foreach(testcase.Actions中的ITestAction操作)
{
WriteLine(String.Format(“{0}-{1}”,testcase.Id,action));
}
}
Console.Read();
}
}
}

好的,我终于自己想出了这个办法。安迪的回答和评论帮助我验证了我的代码是正确的。我刚刚发现我的代码在没有调试时工作得很好!在调试时,我注意到以下几点:


因此,可能是由于某个地方的延迟加载,无法验证附件调试时间的计数(请参阅此处的帖子:)。

谢谢您的回答。我将代码示例复制到一个新的控制台应用程序(.NET Framework 4.6.1),但仍然存在相同的问题。可能与环境有关?@Fokko您确定检查了正确的套件或测试用例吗?我建议您创建一个新项目,然后创建一个测试用例来检查问题是否仍然存在。您也可以在另一台机器上尝试该代码。我在不同的机器上进行了测试,它们都按预期工作。@Fokko您可以尝试使用
ITestCase testcase=ittp.TestCases.Find(22)检查特定的测试用例
查看是否可以检索特定测试用例的测试步骤。
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();
        }
    }
}