Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将接口传递给在C中接受ITestCase类型接口的方法?_C#_Visual Studio 2010_Tfs_Microsoft Test Manager - Fatal编程技术网

C# 如何将接口传递给在C中接受ITestCase类型接口的方法?

C# 如何将接口传递给在C中接受ITestCase类型接口的方法?,c#,visual-studio-2010,tfs,microsoft-test-manager,C#,Visual Studio 2010,Tfs,Microsoft Test Manager,我有一个调用add方法的TestSuite TFS对象。此add方法接受ITestCase作为参数。此ITestCase接口具有以下链接中描述的不同方法和属性: 现在我想传递ITestCase对象,它实现了上面链接中提到的一些方法 var ts = testPlan.TestSuites[i]; var testCase = ts.TestCases.Add(<ITestCase testcase>); 假设您确实想要创建一个真实的测试用例,而不是单元测试或类似测试中的

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

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

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

假设您确实想要创建一个真实的测试用例,而不是单元测试或类似测试中的模拟,那么本文有一个创建一个测试用例的代码示例:

下面是一些经过黑客攻击的代码,它们基于上面的博客条目创建了一个新的测试用例,然后将其添加到名为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中,与目标测试套件关联。

堆栈在哪里?你有实现这个接口的对象吗?@Nathan我已经更新了帖子,添加了两行代码。Gilory,那个博客有在项目级别创建测试用例的代码。我希望它在特定的测试计划,然后在测试套件级别。测试用例属于一个项目。创建测试用例后,我假设您可以将其添加到需要关联的任何测试套件中。如果我遵循链接中共享的方法,它将在何处添加测试用例?在创建的MTM中,我在何处找到测试用例?您可以打开MTM并单击添加新测试的测试套件来找到它个案。我刚刚试过这个-我会在上面的答案中添加代码。非常感谢伊恩。它工作得非常好。我还有一个问题,在执行testcase.save方法之后,当代码执行plan.save方法时,如果执行失败并出现错误,我如何放弃testcase.save更改?如果由于任何原因无法将该工作项添加到TestSuite中,我根本不希望创建该工作项。另外,如果一个测试计划没有任何测试套件,MTM通常将testplan名称作为TestSuite名称。在这种情况下,代码不会在TestSuite下添加测试用例,而是在测试项目级别添加它。