首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过代码在MTM中执行测试

通过代码在MTM中执行测试
EN

Stack Overflow用户
提问于 2014-05-30 12:14:33
回答 2查看 3.5K关注 0票数 1

我在MTM中有一组基于Selenium的测试,它们以单元测试的形式出现。如果我进入MTM并告诉他们跑,我就能让他们跑得很好。我想知道的是,如果有某种API,我可以用来启动这些?

我们有一个用ASP.NET编写的仪表板,我们真正想要的是,如果我们有一个可以执行测试计划的play按钮。我不知道在这方面应该寻找什么,甚至可能的话。

一个可能的解决方案是我构建一个测试工具,并使用反射来运行DLL,但这将是混乱的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-06-09 15:50:14

您可以使用TFS在MTM中执行正在管理的测试。

不幸的是,这个API在MSDN上没有得到很好的记录,这实在令人遗憾.

我的提示:更改MSDN页面上的Visual 2012版本,您将获得更多的文档(仍然太少,但总比没有好.)。

下面是一个示例,说明如何在您选择的测试环境中运行测试计划中属于特定测试套件的所有测试用例:

代码语言:javascript
复制
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();
票数 3
EN

Stack Overflow用户

发布于 2014-05-30 16:23:12

您可以使用MSTEST.exe从命令行运行具有关联自动化的测试用例,而不是使用提供的用户界面。这使您能够从批处理文件自动开始运行。

从命令行运行自动测试从命令行使用MSTest

下面是一个如何做到这一点的例子:

  1. 将MSTEST.EXE添加到您的路径中,我的地址是C:\Program (X86)\MicrosoftVisualStudio12.0\Common7\IDE
  2. 开放cmd
  3. 查看可用的这里命令列表,我将使用/testcontainer和/test
  4. /testcontainer指定.dll的位置。
  5. /test指定要运行哪个测试用例

我的最后命令是

代码语言:javascript
复制
mstest /testcontainer:"C:\Trunk\Project\bin\x86\Debug\TestProject.dll" /test:SmokeTest
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23954379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档