使用 TFS API,我如何在给定的测试套件和计划中获得特定测试用例的结果/结果?
结果/结果是指测试在 MTM 中分组的值:通过、失败、活动、进行中或阻止
我就是这样做的。
为了通过和 totalTests 我使用: ITestRun run*
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
}
}
}
}
}
我希望这可以帮助你。