我在MTM中有一组基于Selenium的测试,它们以单元测试的形式出现。如果我进入MTM并告诉他们跑,我就能让他们跑得很好。我想知道的是,如果有某种API,我可以用来启动这些?
我们有一个用ASP.NET编写的仪表板,我们真正想要的是,如果我们有一个可以执行测试计划的play按钮。我不知道在这方面应该寻找什么,甚至可能的话。
一个可能的解决方案是我构建一个测试工具,并使用反射来运行DLL,但这将是混乱的。
发布于 2014-06-09 15:50:14
您可以使用TFS在MTM中执行正在管理的测试。
不幸的是,这个API在MSDN上没有得到很好的记录,这实在令人遗憾.
我的提示:更改MSDN页面上的Visual 2012版本,您将获得更多的文档(仍然太少,但总比没有好.)。
下面是一个示例,说明如何在您选择的测试环境中运行测试计划中属于特定测试套件的所有测试用例:
string tfsUri= <tfs uri like @"https://<your tfs>/tfs/<your collection>" >;
string userName = <TFS user name>;
string password = <password>,
string projectName = <TFS project name>;
int planId = <test plan id>;
int suiteId = <test suite id>;
int settingsId = <test settings id>;
int configurationId = <test configuration id>;
string environmentName = <test environment you want to run the tests on>;
TfsTeamProjectCollection tfsCollection = new TfsTeamProjectCollection(new Uri(tfsUri), new System.Net.NetworkCredential(userName, password));
tfsCollection.EnsureAuthenticated();
ITestManagementService testManagementService = tfsCollection.GetService<ITestManagementService>();
ITestManagementTeamProject project = testManagementService.GetTeamProject(projectName);
//Get user name
TeamFoundationIdentity tfi = testManagementService.AuthorizedIdentity;
ITestPlan plan = project.TestPlans.Find(planId);
ITestSuiteBase suite = project.TestSuites.Find(suiteId);
ITestSettings testSettings = project.TestSettings.Find(settingsId);
ITestConfiguration testConfiguration = project.TestConfigurations.Find(configurationId);
// Unfortunately test environment name is not exactly the name you see in MTM.
// In order to get the name of your environments just call
// project.TestEnvironments.Query()
// set a breakpoint, run this code in debuger and check the names.
ITestEnvironment testEnvironment = project.TestEnvironments.Find((from te in project.TestEnvironments.Query()
where te.Name.ToUpper().Equals(environmentName.ToUpper())
select te.Id).SingleOrDefault());
ITestRun testRun = plan.CreateTestRun(true);
testRun.Owner = tfi;
testRun.Controller = testEnvironment.ControllerName;
testRun.CopyTestSettings(testSettings);
testRun.TestEnvironmentId = testEnvironment.Id;
testRun.Title = "Tests started from the dashboard";
//Get test points
ITestPointCollection testpoints = plan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + suite.Id + " and ConfigurationId = " + testConfiguration.Id);
foreach (ITestPoint tp in testpoints)
{
testRun.AddTestPoint(tp, tfi);
}
// This call starts your tests!
testRun.Save();发布于 2014-05-30 16:23:12
您可以使用MSTEST.exe从命令行运行具有关联自动化的测试用例,而不是使用提供的用户界面。这使您能够从批处理文件自动开始运行。
见从命令行运行自动测试和从命令行使用MSTest
下面是一个如何做到这一点的例子:
我的最后命令是
mstest /testcontainer:"C:\Trunk\Project\bin\x86\Debug\TestProject.dll" /test:SmokeTesthttps://stackoverflow.com/questions/23954379
复制相似问题