如何在 TFS 中查找给定 ITestCase 对象的所有共享步骤引用

How to find all Shared Step references for a given ITestCase object in TFS

假设我有一个像这样获得的 ITestCase 对象

ITestCase tc = project.TestCases.Find(2034);

其中project是通过

获得的ITestManagementTeamProject类型的对象
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsLocation));
ITestManagementService testService = tfs.GetService<ITestManagementService>();
return testService.GetTeamProject(projectName);

考虑到我没有关于该测试用例的任何先验状态知识,我如何获得该特定测试用例的所有共享步骤引用(甚至不知道一开始是否有一个) .

请帮忙。

有一个 ISharedStepReference Interface 从测试用例调用共享步骤。您只需要使用 FindSharedStep 方法 return 来自服务器的共享步骤定义。示例代码供您参考:

public ISharedStep tstSharedStep { get; private set; }

public ISharedStepReference tstSharedStepRef { get; private set; }

    foreach (ITestAction tstAction in tstCase.Actions)
            {
                tstSharedStep = null; 
                tstSharedStepRef = tstAction as ISharedStepReference;
                    if (tstSharedStepRef != null)
                    {
                        tstSharedStep = tstSharedStepRef.FindSharedStep();
                        foreach (ITestAction tstSharedAction in tstSharedStep.Actions)
                        {
                            ITestStep tstSharedTestStep = tstSharedAction as ITestStep;
                            resultData.Step = Regex.Replace(tstSharedTestStep.Title, @"<[^>]+>|&nbsp;", "").Trim();
                            resultData.ExpectedResult = Regex.Replace(tstSharedTestStep.ExpectedResult, @"<[^>]+>|&nbsp;", "").Trim();

                        }
                    }
                    else {
                     // regular step action
                    }

}