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

时间:2017-08-12 19:24:15

标签: c# tfs tfs2015 tfs-sdk

鉴于我有一个像这样获得的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);

考虑到我对该测试用例没有任何先前的状态知识,我如何获得该特定测试用例的所有共享步骤引用(甚至不知道是否存在一个)。 / p>

请帮忙。

1 个答案:

答案 0 :(得分:1)

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

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
                    }

}
相关问题