使用TFS API,如何在给定的测试套件和计划中获得特定测试用例的结果/结果?
结果/结果是指测试按MTM分组的值: 通过,失败,活动,进行中或被阻止
答案 0 :(得分:1)
我就是这样做的。
要通过和我使用的totalTests: ITestRun运行*
run.PassedTests和run.TotalTests
要查看我使用的运行状态:
TestRunSTate.Aborted和TestRunState.InProgress
要查看是否失败或我使用不确定:
TestOutcome.Failed或TestOutcome.Inconclusive
首先我只使用ITestRun来轻松获得结果,但我发现他们缺少任何类型的"失败"在那里,我觉得非常令人不安。 因此,要将正确的数字发送到邮寄给产品所有者的测试报告中,我在与tfs api交谈时会执行以下操作:
var tfs = Connect(optionsModel.CollectionUri);
var tcm = GetService<ITestManagementService>(tfs);
var wis = GetService<WorkItemStore>(tfs);
_testProject = tcm.GetTeamProject(optionsModel.TeamProjectName);
var plan = _testProject.TestPlans.Find(optionsModel.PlanId);
if (plan == null)
throw new Exception("Could not find plan with that id.");
var run = plan.CreateTestRun(true);
var testSuite = _testProject.TestSuites.Find(optionsModel.SuiteId);
if (testSuite == null)
throw new Exception("Could not find suite with that id.");
AddTestCasesBySuite(testSuite, optionsModel.ConfigId, plan, run);
run.Title = optionsModel.Title;
run.Save();
var failedTests = run.QueryResultsByOutcome(TestOutcome.Failed).Count;
var inconclusiveTests = run.QueryResultsByOutcome(TestOutcome.Inconclusive).Count;
希望这会有所帮助 optionsmodel是我从运行tsts的用户那里获取的信息
答案 1 :(得分:0)
我试图做同样的事情,但是使用了REST API。
以防万一,有人设法从套件中获取测试点:
https://dev.azure.com/{organization}/{project}/_apis/testplan/Plans/{planId}/Suites/{suiteId}/TestPoint?api-version=5.1-preview.2
答案 2 :(得分:-1)
您可以使用ITestManagementService
和TestPlan
查询来获取特定测试计划的结果
var server = new Uri("http://servername:8080/tfs/collectionname");
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(server);
var service = tfs.GetService<ITestManagementService>();
var testProject = service.GetTeamProject(teamProject);
var plans = testProject.TestPlans.Query("SELECT * FROM TestPlan").Where(tp => tp.Name == YOURTESTPLANNAME).FirstOrDefault();
ITestPlanCollection plans = tfsConnectedTeamProject.TestPlans.Query("Select * From TestPlan");
foreach (ITestPlan plan in plans)
{
if (plan.RootSuite != null && plan.RootSuite.Entries.Count > 0)
{
foreach (ITestSuiteEntry suiteEntry in plan.RootSuite.Entries)
{
var suite = suiteEntry.TestSuite as IStaticTestSuite;
if (suite != null)
{
ITestSuiteEntryCollection suiteentrys = suite.TestCases;
foreach (ITestSuiteEntry testcase in suiteentrys)
{
// Write code to get the test case
}
}
}
}
}
我希望这对你有所帮助。