gpt4 book ai didi

c# - 通过代码在 MTM 中执行测试

转载 作者:太空宇宙 更新时间:2023-11-03 20:05:19 25 4
gpt4 key购买 nike

我在 MTM 中有一组基于 Selenium 的测试,它们采用单元测试的形式。如果我进入 MTM 并告诉他们运行,我就能很好地运行它们。我想知道是否有某种 API 可以用来启动它们?

我们有一个用 ASP.NET 编写的仪表板,我们真正想要的是我们是否可以有一个可以执行测试计划的播放按钮。我不太确定在这方面要搜索什么,甚至根本不确定。

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

最佳答案

您可以使用 TFS API 执行您在 MTM 中管理的测试。
不幸的是,这个 APIMSDN 上的文档非常少,这真的很遗憾......
我的提示:在 MSDN 页面上更改为 Visual Studio 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();

关于c# - 通过代码在 MTM 中执行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23954379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com