2013-06-24 166 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(); 
    } 
相關問題