2017-08-12 81 views
1

假设我有一个像这样如何找到一个给定ITestCase对象的所有共享步骤引用在TFS

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

project

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

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

请帮忙。

回答

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 
        } 

} 
+0

真棒。谢谢。最后一个问题是,如果我需要删除共享步骤引用,那么删除该测试用例的所有操作是否可以完成这项工作? –

+1

@SohamDasgupta是的,你可以使用'TestCase.Actions.Remove(xx)'来做到这一点。以下是一些代码示例的相关主题:https://social.msdn.microsoft.com/Forums/vstudio/en-US/426b46f0-6a73-4f09-bc7a-83243e803c57/problem-using-the-ite-casestatlectionremove-function?论坛= vsmantest –

相关问题