我目前正在開發一個程序來執行程序中的測試用例,並且我已經查看了How to create a test run and result using the Team Foundation Server API?以及其他各種文章,並且仍然有很多麻煩。我的目標是找到一個具有特定標題和配置的測試用例,執行它並在失敗時添加註釋。這裏只是一些代碼,我一直在瞎搞與使用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);
這是我得到的錯誤行「的NullReferenceException是未處理」這套房,但對象看起來不錯。請讓我知道,如果你能幫助:)
不完整的答案。給出正確使用的例子。 – mtadd
對我來說,更像是在創建一個ITestPlan plan = teamProject.TestPlans.Create();你需要將它保存到實際的tfs上。也就是說,在plan.RootSuite.Entries.Add(suite)之前,您需要添加一個plan.Save(); – Qiang