2012-08-15 49 views
-1

我有它调用一个附加方法。这种添加方法接受ITestCase作为参数。这ITestCase界面具有在低于链路描述的不同的方法和属性一个TestSuite(TFS对象)对象:如何将接口传递给接受C#中ITestCase类型接口的方法?

http://msdn.microsoft.com/en-us/library/dd984690

现在我想要通过实现上述链接中提到的一些方法的ITestCase对象。

var ts = testPlan.TestSuites[i]; 
    var testCase = ts.TestCases.Add(<ITestCase testcase>); 
+0

你在哪堆叠?你有一个实现这个接口的对象吗? – elyashiv 2012-08-15 15:44:59

+0

@Nathan我已更新帖子以添加两行代码。 – krrishna 2012-08-15 16:59:55

回答

1

假设你真的想建立一个真正的考验的情况下,而不是在一个单元测试(或类似)一个模拟的,那么这个博客帖子有它创建一个代码示例:http://www.ewaldhofman.nl/post/2009/12/11/TFS-SDK-2010-e28093-Part-5-e28093-Create-a-new-Test-Case-work-item.aspx

以下是一些基于上述博客条目创建新测试用例的代码,然后将其添加到现有测试套件(名为“ExampleSuite2”,位于名为“TfsVersioning Test Plan”的测试计划中) ):

var tfsUri = new Uri("http://localhost:8080/tfs/"); 
var tfsConfigServer = new TfsConfigurationServer(tfsUri, new UICredentialsProvider()); 
tfsConfigServer.EnsureAuthenticated(); 

var projCollectionNode = tfsConfigServer.CatalogNode.QueryChildren(new[] {CatalogResourceTypes.ProjectCollection}, false,                CatalogQueryOptions.None).FirstOrDefault(); 
var collectionId = new Guid(projCollectionNode.Resource.Properties["InstanceId"]); 
var projCollection = tfsConfigServer.GetTeamProjectCollection(collectionId); 

ITestManagementService tms = projCollection.GetService<ITestManagementService>(); 
var project = tms.GetTeamProject("TfsVersioning"); 

var testCase = project.TestCases.Create(); 
testCase.Title = "Browse my blog"; 
var navigateToSiteStep = testCase.CreateTestStep(); 
navigateToSiteStep.Title = "Navigate to \"http://www.ewaldhofman.nl\""; 
testCase.Actions.Add(navigateToSiteStep); 

var clickOnFirstPostStep = testCase.CreateTestStep(); 
clickOnFirstPostStep.Title = "Click on the first post in the summary"; 
clickOnFirstPostStep.ExpectedResult = "The details of the post are visible"; 
testCase.Actions.Add(clickOnFirstPostStep); 
testCase.Save(); 

//Add test case to an existing test suite 
var plans = project.TestPlans.Query("SELECT * FROM TestPlan where PlanName = 'TfsVersioning Test Plan'"); 
var plan = plans.First(); 
var firstMatchingSuite = project.TestSuites.Query("SELECT * FROM TestSuite where Title = 'ExampleSuite2'").First(); 
((IStaticTestSuite)firstMatchingSuite).Entries.Add(testCase); 
plan.Save(); 

运行此代码后,新的测试用例出现在与目标测试套件相关的MTM中。

+0

Gilory,该博客的代码可以在项目级别创建测试用例。我希望在特定的测试计划中测试,然后在测试套件级别测试用例 – krrishna 2012-08-15 16:10:47

+0

测试用例属于一个项目。在创建测试用例之后,我假设您可以将其添加到您需要与之关联的任何测试套件中。 – 2012-08-15 16:19:47

+0

如果我遵循链接中共享的方法,它会在哪里添加测试用例?我在哪里可以找到创建的MTM中的测试用例? – krrishna 2012-08-16 05:33:21

相关问题