Share via


Query Last Test run results

Hello All,

This is my first post here on MSDN blogs. And, to keep little different, I'm directly pitching in to the topic that I want to blog rather than starting with formal introduction about me. So, here I go …

I've been searching on the net for the code snippet to query the "Last test run results" of one or more test cases being associated to one or more Test Suite -> Test plan in TFS2010. And finally, I ended-up with no clue on how to query the following items using TFS 2010 SDK. And, thereafter, with sub-sequent discussion with internal MSFT folks, I was able to come-up with a piece of code that can generate the complete traceability of test results starting from Test Plan -> Test Suite -> Test Case - > Last Test Run results - as shown below:

Code snippet to query Test plan:

public ITestPlanCollection GetTestPlan(ITestManagementTeamProject testManagementTeamProject, string testPlan)

{

ITestPlanCollection mTestPlanCollection = null;

// Build TFS Query based on Test plan

if (string.IsNullOrEmpty(testPlan))

mTestPlanCollection = testManagementTeamProject.TestPlans.Query("Select * From TestPlan");

else

mTestPlanCollection = testManagementTeamProject.TestPlans.Query(string.Format("Select * From TestPlan where PlanName = '{0}'", testPlan));

return mTestPlanCollection;

}

Query the Test suites, test cases and associated test results:

// Loop through the test plan collection to read the associated test suite.

foreach (ITestPlan testPlan in testPlanCollection)

{

// Loop through the test suite to read the associated test case.

foreach (ITestSuiteBase testSuite in testPlan.RootSuite.SubSuites)

{

// Query Test points that holds the Test case and test result information

foreach (ITestPoint point in testPlan.QueryTestPoints(string.Format("SELECT * FROM TestPoint WHERE SuiteId = {0}", testSuite.Id)))

{

ITestCaseResult testResult = point.MostRecentResult;

if (point.MostRecentResult == null)

{

// test case is not executed at least once.

}

else

{

switch (testResult.Outcome)

{

case TestOutcome.Passed:

// based on test outcome increase your counter

break;

case TestOutcome.Failed:

// based on test outcome increase your counter

break;

case TestOutcome.Unspecified:

// based on test outcome increase your counter

break;

}

}

}

}

}

- thiru V

Comments

  • Anonymous
    December 28, 2010
    i don't understand test well. but congrats on ur first post :)

  • Anonymous
    December 29, 2010
    Thiru, very neat and elegant code. Thanks for sharing

  • Anonymous
    July 21, 2011
    The comment has been removed

  • Anonymous
    June 17, 2013
    There would be no way to piece together the MSDN documentation to determine this.  Thanks for the post.

  • Anonymous
    July 08, 2014
    Hi, I have been looking for some thing like this but this is the first post coming across. so thanks a lot but can you please also tell me how to use it? I don't have much of a technical background. Is this just a sql query that I can run in the management studio? and what are these two different piece of codes? and how do I use both of them.

  • Anonymous
    July 08, 2014
    My email id is de.foru@gmail.com. Please email me your response. Many thanks.