Reputation: 3511
Is there a way I can get the test runs executed against a test plan id programmatically ? Also i want to get the results for say last 30 day or last X days?
To get the test case results for a particular test run, I am using below query,
var results = proj.TestResults.Query(string.Format("SELECT * FROM TestResult WHERE TestRunId =" + testRunId + ""));
Upvotes: 1
Views: 3149
Reputation: 5010
To get test runs against a test plan id:
TfsTeamProjectCollection tfctc = new TfsTeamProjectCollection(new Uri("http://tfsservername:8080/tfs/DefaultCollection"));
ITestManagementService testmanagementService = tfctc.GetService<ITestManagementService>();
var teamproject = testmanagementService.GetTeamProject("teamprojectname");
var testruns = testmanagementService.QueryTestRuns("select * From TestRun");
List<ITestRun> testrunInPlan = new List<ITestRun>();
foreach (var testrun in testruns)
{
if (testrun.TestPlanId==31) // in this case TestPlanId is 31
{
testrunInPlan.Add(testrun);
}
}
To get test case result for a particular test run:
ITestCaseResultCollection testcases = testrun.QueryResults();
foreach (ITestCaseResult testcase in testcases)
{
Console.WriteLine("TestCase ID: " + testcase.TestCaseId);
Console.WriteLine("TestCase Title: " + testcase.TestCaseTitle);
Console.WriteLine("Error Message: " + testcase.ErrorMessage);
}
Please check this blog for the details on Test Management API: http://blogs.msdn.com/b/aseemb/archive/2012/08/07/code-snippets-on-test-management-apis.aspx
Upvotes: 2