【发布时间】:2020-07-17 03:39:52
【问题描述】:
使用 TFS API,我如何获得给定测试套件和计划中特定测试用例的结果/结果?
对于结果/结果,我的意思是测试在 MTM 中分组的值: 通过、失败、活动、进行中或被阻止
【问题讨论】:
-
谢谢,但这并不是我真正想要的。正如我所说,我想找出给定特定测试用例 ID 的结果。
标签: tfs-sdk
使用 TFS API,我如何获得给定测试套件和计划中特定测试用例的结果/结果?
对于结果/结果,我的意思是测试在 MTM 中分组的值: 通过、失败、活动、进行中或被阻止
【问题讨论】:
标签: tfs-sdk
我就是这样做的。
要通过和 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 的用户那里获取的信息
【讨论】:
我试图做同样的事情,但使用的是 REST API。
以防万一它对某人有帮助,我设法从套件中获取测试点:
https://dev.azure.com/{organization}/{project}/_apis/testplan/Plans/{planId}/Suites/{suiteId}/TestPoint?api-version=5.1-preview.2
【讨论】:
您可以使用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
}
}
}
}
}
希望对你有帮助。
【讨论】: