2013-06-24 64 views
3

我试图使用TFS API来更新单独运行的自动化测试结果。我尝试了其他问题的建议(特别是How to create a test run and result using the Team Foundation Server API?)以及其他地方的搜索。不管我怎么努力我有同样的问题:每次我试图将一个测试点添加到试运行的时候,我收到错误 -TFS 2012 API:无法将测试点添加到测试运行

Microsoft.TeamFoundation.TestManagement.Client.TestManagementInvalidOperationException: This test run cannot be created with the test points. 

测试点由TFS使用WIQL检索,和我检查每个测试点在我尝试添加测试计划,测试套件和测试配置之前要确保它是正确的。

我无法保存没有测试点的测试运行。

private void ConfigureTestRun() 
    { 
     this.Run.DateStarted = DateTime.Now; 
     this.Run.DateCompleted = DateTime.Now; 
     // find the points that correspond to test cases in the run suite 
     foreach (ITestPoint point in this.Points) 
     { 
      if (point.TestCaseExists && point.Plan.Id == this.Plan.Id && point.ConfigurationId == this.Config.Id) 
      { 
       this.Run.AddTestPoint(point, this.CurrentUser); // fails with InvalidOperationException 
      } 
     } 

     this.Run.Save(); 
    } 

我能:

示例代码

public void UpdateTests(TestSuiteRun suiteRun) 
    { 


     this.Config = FindConfig(suiteRun.Description); 
     this.Suite = FindSuite(suiteRun.Name); 
     this.Plan = Suite.Plan; 
     this.Points = FindPoints(this.Suite.Id, this.Config.Id); 
     ITestCaseCollection testCases = Suite.AllTestCases; 
     this.Run = TeamProject.TestRuns.Create(); 
     ConfigureTestRun(); // failing here 

     this.Result = CreateRunResults(); 

     this.Iteration = CreateSingleIteration(suiteRun.Description); 
     { 
      UpdateResultsForScenario(scen); 
     } 


    } 

而且方法来配置试运行(我已经经历了这么多努力,现在我的代码已经超出了凌乱)连接到TFS并检索我需要的所有数据,但将测试点添加到新的测试运行正在让我发疯。

我做错了什么?

+0

什么是“保存”的回报,如果它是一个布尔值,什么是结果? – DaveShaw

+0

@DaveShaw我没有去“保存” - 例程在Run.AddTestPoint()上失败。 –

回答

1

经过疯狂的试验并将我的头靠在墙上敲了一下之后,我找到了答案。

对于那些谁是好奇,这里是它的工作原理是:

  • 如果我创建使用 ITestManagementService.TestRuns.Create();我可以添加测试用例,但 没有测试点的测试运行。

  • 如果我使用 ITestPlan.CreateTestRun(isAutomated);创建测试运行,我可以添加测试点,但不能添加 测试用例。

我过于复杂的事情很多试图得到这个工作 - 我现在已经清理了很多的混乱,并有我的应用程序正确地报告测试结果TFS。

我按照Jason Prickett's blog的说明使用了一个或多或少的伪造版本。

我发现的一件事是,我无法将运行定义为自动运行,因为我的环境中没有测试运行控制器,并且找不到将测试运行状态从WaitingForController移动到Completed的方法。

还有更多的清理走,但核心的工作是这样的:

 this.Run = this.Plan.CreateTestRun(false); 
     ConfigureTestRun(build); 

     this.Result = CreateRunResults(); 

     this.Iteration = CreateSingleIteration(suiteRun.Description); 

// custom processing omitted for brevity 

     this.Result.Iterations.Add(this.Iteration); 
     // Attach the run log to the results 
     ITestAttachment item = this.Iteration.CreateAttachment(ConfigurationManager.AppSettings["LogFile"], SourceFileAction.None); 
     this.Result.State = TestResultState.Completed; 
     this.Result.Save(); 
     this.Run.Attachments.Add(item); 
     this.Run.Save(); 

而且试运行配置程序是:

private void ConfigureTestRun(IBuildDetail build) 
    { 
     this.Run.DateStarted = DateTime.Now; 
     this.Run.DateCompleted = DateTime.Now; 
     this.Run.BuildDirectory = build.DropLocation; 
     this.Run.BuildFlavor = "debug"; 
     this.Run.BuildNumber = build.BuildNumber; 
     this.Run.BuildPlatform = "test platform"; 
     this.Run.BuildUri = build.Uri; 
     this.Run.Controller = build.BuildController.Name; 


     // find the points that correspond to test cases in the run suite 
     foreach (ITestPoint point in this.Points) 
     { 
      if (point.TestCaseExists && point.Plan.Id == this.Plan.Id && point.ConfigurationId == this.Config.Id) 
      { 
       this.Run.AddTestPoint(point, this.CurrentUser); 
      } 
     } 

     this.Run.Save(); 
    }