2012-08-15 47 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

相關問題