-1

我有一个调用 add 方法的 TestSuite(TFS 对象)对象。此 add 方法接受 ITestCase 作为参数。此 ITestCase 接口具有以下链接中描述的不同方法和属性:

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

现在我想传递 ITestCase 对象,它实现了上面链接中提到的一些方法。

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

1 回答 1

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 测试计划”的测试计划中):

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 中,与目标测试套件相关联。

于 2012-08-15T15:56:35.593 回答