2012-07-03 3 views
4

현재 프로그램에서 테스트 사례를 실행하는 프로그램을 작성 중이며 How to create a test run and result using the Team Foundation Server API?과 기타 다양한 기사를 보았으며 여전히 많은 문제가 있습니다. 내 목표는 특정 제목 및 구성을 가진 테스트 사례를 찾고 실행하고 실패한 경우 메모를 추가하는 것입니다. 여기에 내가 "NullReferenceException이 처리되지 않은이었다"나는 오류 라인입니다TFS API를 사용하여 테스트 케이스를 실행 (통과/실패)합니까?

 String server = "http://tfs.net:8080/tfs"; 
     String project = "Project"; 
     // Connect to the TeamFoundationServer. 
     Console.Write("Connecting to Team Foundation Server {0}...\n", server); 

     TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(server)); 
     Console.WriteLine("Success!\n"); 
     Console.WriteLine("getting project {0}...\n", project); 

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

     Console.WriteLine("Success!\nGetting test cases...\n\n"); 
     IEnumerable<ITestCase> testCases = teamProject.TestCases.Query("SELECT [Title] FROM WorkItems WHERE State = 'Ready' AND Title CONTAINS 'Phase 1: test case title'"); 
     foreach (ITestCase t in testCases) 
      Console.WriteLine(t.Title); 
     ITestSuiteCollection suites = teamProject.TestSuites.Query("SELECT * FROM TestSuite"); 



     ITestConfigurationCollection configs = teamProject.TestConfigurations.Query("Select * FROM TestConfiguration WHERE Name='Mainline Android Phone 2.3'"); 
     ITestConfiguration config = configs[0]; 

     ITestPlan plan = teamProject.TestPlans.Create(); 
     plan.Name = "herpa derp"; 

     ITestSuiteBase suite = teamProject.TestSuites.Find(606); 


     Console.WriteLine(plan.Name); 
     Console.WriteLine(suite.Title); 
     plan.RootSuite.Entries.Add(suite);//Object reference not set to an instance of an object. 
     plan.Save(); 

     suite.TestCases.AddCases(testCases); 
     plan.Save(); 

     ITestRun run = plan.CreateTestRun(false); 


     ITestPointCollection points = plan.QueryTestPoints("SELECT * FROM TestPoint"); 
     foreach (ITestPoint p in points) 
     { 
      run.AddTestPoint(p, null); 
     } 
     run.Save(); 
     ITestCaseResult result = run.QueryResults()[0]; 
     result.Outcome = TestOutcome.Passed; 
     result.Save(); 

     //wait dood 
     Console.Read(); 

plan.RootSuite.Entries.Add(suite); 와 장난 한 그냥 코드는 스위트 룸,하지만 개체가 잘 보인다. 도움을 주실 수 있으면 알려주십시오.

답변

0

계획에 전달하는 데 필요한 모든 입력란을 보려면 teamProject에 대한 적절한 액세스 권한이없는 것 같습니다.

0

루트 항목을 추가하기 전에 계획을 저장하십시오.

+0

불완전한 답변입니다. 적절한 사용법의 예를 든다. – mtadd

+0

나에게 그것은 ITestPlan plan = teamProject.TestPlans.Create(); 당신은 실제로 그것을 tfs에 저장해야합니다. 계획하기 전에 말이야. 루트 스위트. 에드 트리 (계획)를 추가해야합니다. 세이브(); – Qiang

관련 문제