【问题标题】:Get test outcome/result using TFS API使用 TFS API 获取测试结果/结果
【发布时间】:2020-07-17 03:39:52
【问题描述】:

使用 TFS API,我如何获得给定测试套件和计划中特定测试用例的结果/结果?

对于结果/结果,我的意思是测试在 MTM 中分组的值: 通过、失败、活动、进行中或被阻止

【问题讨论】:

标签: tfs-sdk


【解决方案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 的用户那里获取的信息

【讨论】:

    【解决方案2】:

    我试图做同样的事情,但使用的是 REST API。

    以防万一它对某人有帮助,我设法从套件中获取测试点:

    https://dev.azure.com/{organization}/{project}/_apis/testplan/Plans/{planId}/Suites/{suiteId}/TestPoint?api-version=5.1-preview.2
    

    更多信息:https://docs.microsoft.com/en-us/rest/api/azure/devops/testplan/test%20point/get%20points%20list?view=azure-devops-rest-5.1

    【讨论】:

      【解决方案3】:

      您可以使用ITestManagementServiceTestPlan 查询来获取特定测试计划的结果

          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 
                              }
                          }
                      }
                  }
              }
      

      希望对你有帮助。

      【讨论】:

      • 这个答案不包含如何获得测试用例的结果/结果,只包含如何迭代测试计划和测试套件。
      猜你喜欢
      • 2018-12-10
      • 2017-01-15
      • 2015-12-25
      • 1970-01-01
      • 2014-03-11
      • 1970-01-01
      • 2013-04-12
      • 2018-10-05
      • 1970-01-01
      相关资源
      最近更新 更多