2016-10-21 8 views
0

私はTFSテスト結果を実行した構成に対してのみ更新するように働いているようです。しかし、それは非常に非効率なようです。誰かが私が間違っていることを理解するのを助けることができますか? - 具体的には、特定のテストIDのtestSuitesを取得してから、それらのスイートのすべてのテストを繰り返して、すでに持っているテストIDと比較する必要があるように見えるわけではありません。設定によってTFSテスト結果を更新するにはどうすればよいですか?

例として、Windows 8/Chromeに対してテストを実行します。したがって、TestContextには、構成にマップされる適切な値が含まれています。私はそれが中に存在するすべてのテストスイートには、その構成のためのテスト結果を更新したいここでは、コードです:。

public void UpdateResult(TestContext context, bool passed) 
    { 
     int testCaseID = Convert.ToInt32(context.Test.Properties["id"]); 

     TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri); 

     ITestManagementService service = projectCollection.GetService<ITestManagementService>(); 
     ITestManagementTeamProject teamProject = service.GetTeamProject(teamProjectName); 

     ITestCase testCase = teamProject.TestCases.Find(testCaseID); 
     ITestSuiteCollection testSuites = teamProject.TestSuites.ReferencingTestCase(testCaseID); 

     if (testCase != null) 
     { 
      // ---- Get Test Plan 
      int testPlanId = 20589; 
      ITestPlan testPlan = teamProject.TestPlans.Find(testPlanId); 

      // ---- Create Test Run 
      ITestRun testRun = teamProject.TestRuns.Create(); 
      testRun = testPlan.CreateTestRun(true); 

      // ---- Get TestPoint 
      ITestPointCollection points = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE TestCaseId =" + testCaseID); 
      foreach (ITestPoint tp in points) 
      { 
       //Get configuration, which contains configuration values 
       ITestConfiguration testConfiguration = teamProject.TestConfigurations.Query("Select * from TestConfiguration WHERE Name='" + tp.ConfigurationName + "'")[0]; 
       IDictionary<string, string> testConfigValues = testConfiguration.Values; 

       if ((!testConfigValues.ContainsKey("Browser") || 
        testConfigValues["Browser"].ToLower() == context.Test.Properties["Browser"].ToString().ToLower()) 
        && (!testConfigValues.ContainsKey("Operating System") || 
        testConfigValues["Operating System"].ToLower() == context.Test.Properties["Operating System"].ToString().ToLower()) 
        ) 
       { 
        testRun.AddTestPoint(tp, testPlan.Owner); 
       } 

      } 

      testRun.State = TestRunState.Completed; 
      testRun.Save(); 

      foreach (ITestSuiteBase testSuite in testSuites) 
      { 
       foreach (ITestSuiteEntry testCse in testSuite.TestCases) 
       { 
        ITestCaseResultCollection results = testRun.QueryResults(); 
        if (testCse.TestCase.Id == testCaseID) 
        { 

         foreach (IdAndName config in testCse.Configurations) 
         { 
          IEnumerable<ITestCaseResult> testCaseResults = from tr in results 
                      where 
                      tr.TestConfigurationId == config.Id && 
                      tr.TestCaseId == testCase.Id 
                      select tr; 

          foreach (ITestCaseResult result in testCaseResults) 
          { 
           result.Outcome = passed ? TestOutcome.Passed : TestOutcome.Failed; 
           result.State = TestResultState.Completed; 
           result.Save(true); 
          } 
         } 
        } 


       } 
      } 

      testRun.Save(); 
      testRun.Refresh(); 
     } 
    } 

答えて

0

テスト結果を取得するためには、あなたが直接、テストIDにより検査結果を得ることができます。たとえば、次のように

TfsTeamProjectCollection teamCollection; 
      ITestManagementService service; 
      ITestManagementTeamProject project; 
      var picker = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false); 
      picker.ShowDialog(); 
      if (picker.SelectedTeamProjectCollection != null && picker.SelectedProjects != null) 
      { 
       teamCollection = picker.SelectedTeamProjectCollection; 
       service = teamCollection.GetService<ITestManagementService>(); 
       project = service.GetTeamProject(picker.SelectedProjects.First().Name); 
      } 
      else 
      { 
       return; 
      } 

//Get Test result 
var testResults = project.TestResults.ByTestId([test case id]); 

// iterate each result for the case 
foreach (ITestCaseResult result in testResults) 
{ 
    //TODO other code 
    //update result 
    result.Outcome = TestOutcome.Failed; 
    result.Save(true); 
} 

もご参考のためにあなたを助けるかもしれ関連TFS APIについてのいくつかのリンクを追加します。これは、プログラムである必要がありますので、

+0

をピッカーは私にはあまり効果がありません。だから私は有用な部分がtestResults ByTestIdを取得していると仮定しています。それは参考になると分かりましたが、それは私の考えを解決しません。私が投稿した怪物をしない限り、私の問題はすべての構成の更新です。選択した構成をコードにのみ更新する方法を組み込むにはどうすればよいですか?また、AddTestPointを呼び出す必要はありませんか? –

+0

あなたのコメントをお寄せください?私はあなたが与えたリンクを見てきましたが、アップデートにどのようにコンフィギュレーションを組み込むかについては話しません。 –

関連する問題