I have created a project that connects to the server and then gets the test plans, but I'm struggling with getting the test plan results (number of passed, failed and active test cases). The code below is the code I use for getting the test plans. Any suggestions on how to get the test results for these plans? Or how can I get test run results for a single test case. I can filter out the test plans, suites and cases I want to, but I can't find results anywhere.
void GetTestPlans(ITestManagementTeamProject testproject)
{
ITestPlanCollection plans = testproject.TestPlans.Query("Select * From TestPlan");
TreeViewItem root = null;
root = new TreeViewItem();
root.Header = ImageHelpers.CreateHeader(testproject.WitProject.Name, ItemTypes.TeamProject);
TreeMain.Items.Add(root);
foreach (ITestPlan plan in plans)
{
if (plan.Name.Contains("C600 Update"))
{
TreeViewItem plan_tree = new TreeViewItem();
string header = plan.Id + "\t" + plan.Name;
plan_tree.Header = ImageHelpers.CreateHeader(header, ItemTypes.TestPlan);
if (plan.RootSuite != null && plan.RootSuite.Entries.Count > 0)
GetPlanSuites(plan.RootSuite.Entries, plan_tree);
root.Items.Add(plan_tree);
}
}
}
void GetPlanSuites(ITestSuiteEntryCollection suites, TreeViewItem tree_item)
{
foreach (ITestSuiteEntry suite_entry in suites)
{
IStaticTestSuite suite = suite_entry.TestSuite as IStaticTestSuite;
if (suite != null)
{
TreeViewItem suite_tree = new TreeViewItem();
suite_tree.Header = ImageHelpers.CreateHeader(suite.Title, ItemTypes.TestSuite);
GetTestCases(suite, suite_tree);
tree_item.Items.Add(suite_tree);
if (suite.Entries.Count > 0)
GetPlanSuites(suite.Entries, suite_tree);
}
}
}
void GetTestCases(IStaticTestSuite suite, TreeViewItem tree_item)
{
//AllTestCases - Will show all the Test Cases under that Suite even in sub suites.
//ITestCaseCollection testcases = suite.AllTestCases;
//Will bring only the Test Case under a specific Test Suite.
ITestSuiteEntryCollection suiteentrys = suite.TestCases;
foreach (ITestSuiteEntry testcase in suiteentrys)
{
ITestCase testCase = testcase.TestCase as ITestCase;
TreeViewItem test = new TreeViewItem();
string header = testcase.Id + "\t" + testcase.Title;
test.Header = ImageHelpers.CreateHeader(header, ItemTypes.TestCase);
tree_item.Items.Add(test);
GetResults(testCase);
}
}
void GetResults(ITestCase testCase)
{
// Would like to get the results for each test case here
// If there are several test runs, only the latest counts
}