我正在尝试使用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
}
}
任何?
答案 0 :(得分:0)
您可以使用以下示例从特定测试套件中检索测试用例步骤,它可以在我这边工作:
安装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();
}
}
}
答案 1 :(得分:0)
所以可能因为某处的延迟加载,无法验证附件调试时间的计数(请参阅此处的帖子:Lazy<T>: "The function evaluation requires all threads to run")。