I am currently working on a program to run test cases in a program, and I looked at How to create a test run and result using the Team Foundation Server API? as well as various other articles, and I still have a lot of problems. My goal is to find a test case with a specific title and configuration, execute it and add notes if it fails. Here is just some code that I messed with
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); this is the line where I get the error "nullreferenceexception was unhandled", this is a package, but the object looks great. Please let me know if you can help :)
source share