2013-05-27 50 views
3

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

与预后/结果我的意思是测试由MTM分组的值: 通过,失败,主动,正在进行或阻塞

MTM test case outcome/result

+0

你可能想看看这个 http://stackoverflow.com/questions/8731854/querying-failed-unit-tests-from-tfs-sdk – Florian

+0

谢谢,但是这不是真的什么我寻找。正如我所说的,我想知道给定的测试用例ID的结果。 – Oskar

回答

-1

您可以使用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 
         } 
        } 
       } 
      } 
     } 

我希望这可以帮到你。

+1

此答案不包含有关如何获得测试用例的结果/结果的内容,仅包含如何遍历测试计划和测试套件。 – Oskar

1

这就是我的做法。

要获得通过,并totalTests我用: ITestRun运行*

run.PassedTests和run.TotalTests

要查看运行状态,我用:

TestRunSTate.Aborted和TestRunState.InProgress

要查看是否失败或不确定我使用:

TestOutcome.Failed或TestOutco me.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