TFS 2010 API - Get Results of a Test Run

TFS 2010 API - Get Results of a Test Run

The Results of a Test Run can be obtained by using TFS 2010 API

You first need to add a reference to Microsoft.TeamFoundation.Client.dll and Microsoft.TeamFoundation.TestManagement.Client.dll

These dll can be found under C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies

The below code describes how to obtain Failed test cases of a Test Run

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(http://%3cserver%3e:8080/tfs/%3Ccollection%3E));

ITestManagementService testManagement = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));

ITestManagementTeamProject testManagementTeamProject = testManagement.GetTeamProject(teamProject);

// _testRunID is the Run ID of the Test Run

ITestRun testRun = testManagementTeamProject.TestRuns.Find(_testRunID);

// Get Failed Test Cases

ITestCaseResultCollection testcases = testRun.QueryResultsByOutcome(TestOutcome.Failed);

foreach (ITestCaseResult testcase in testcases)


       // Print Test Case Details

       Console.WriteLine("TestCase ID: " + testcase.TestCaseId);

       Console.WriteLine("TestCase Title: " + testcase.TestCaseTitle);

       Console.WriteLine("Error Message: " + testcase.ErrorMessage);


Similarly test cases which are Passed, Aborted, etc. can be found out by passing TestOutcome.Passed , TestOutcome.Aborted, etc

Leave a Comment
  • Please add 3 and 4 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
  • TejasJ edited Revision 2. Comment: tags edit.

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
  • I have an ordered test with 13 cases.When i use  ITestCaseResultCollection testcases = testRun.QueryResultsByOutcome(TestOutcome.Failed); i am getting the result of ordered Test.But is there any way to get the test Case result of the test cases within the ordered test

  • As far as I know, there is no direct way to get individual test level details of an ordered test.

  • TejasJ edited Revision 2. Comment: tags edit.

  • I get the following error:Error

    The type 'System.Collections.Specialized.INotifyCollectionChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'WindowsBase, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

    I've included a using System.Collection.Specialized, but this doesn't resolve it.

  • Just in case someone else sees this, I found the problem.  I had to include WindowsBase.dll

Page 1 of 1 (5 items)