假設你真的想建立一個真正的考驗的情況下,而不是在一個單元測試(或類似)一個模擬的,那麼這個博客帖子有它創建一個代碼示例: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中。
你在哪堆疊?你有一個實現這個接口的對象嗎? – elyashiv 2012-08-15 15:44:59
@Nathan我已更新帖子以添加兩行代碼。 – krrishna 2012-08-15 16:59:55