In a report, I need to present all test results for a certain test plan.
Currently I am using the following function:
foreach (TestCase testCase in testCasesByWorkItem)
{
List<ITestCaseResult> testCaseResults = teamProject.TestResults.ByTestId(testCase.TestCaseId).Where(x => x.State == TestResultState.Completed).ToList();
....
}
My understanding is that it returns all results for this test case, and one test case may belong to many test plans.
My problem is performance. The operation takes up to 25 seconds (in debug mode), and I have thousands of test cases.
I only need those test case results, that belong to a certain test plan.
For example, TestCaseX may have been executed for test plans Release1.0, Release2.0, .... Release20.0. And I am only interested in results for Release15.0.
Currently I retrieve results as above, and later filter by a correct test plan.
Is there a way to optimize performance by somehow only selecting test results that belong to a given test plan?
You can use below sample 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);
}
}
And below sample 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