问题
I am working with a school project where I am going to analyse a companies defect database. They are using Microsoft Foundation Server (TFS). I am all new to TFS and the TFS api.
I have some problem in getting the right data from TFS using the TFS Client Object Model . I can retrieve all Test Plans, their respective test suites and every test case that a specific test suite uses, but the problem comes when I want to see in which test suite I have a specific test result from a test case. Since more than one the suite can use the same test cases, I cant see in which suite the result came from.
I am doing this way in getting test cases from suites:
foreach (ITestSuiteEntry testcase in suiteEntrys)
{
Console.WriteLine("\t \t Test Case: {0}", testcase.Title+", "+"Test case priority: "+ testcase.TestCase.Priority+"Test case Id: "+testcase.TestCase.Id);
//Console.Write(", Test Case: {0}", testcase.ToString());
//get each test result:
getTestResult(testcase,proj);
}
private void getTestResult(ITestSuiteEntry testcase, ITestManagementTeamProject proj)
{
var testResults = proj.TestResults.ByTestId(testcase.TestCase.Id);
foreach (ITestCaseResult result in testResults)
{
Console.WriteLine("\t \t \t"+result.DateCreated+","+result.Outcome);
}
}
So my question is, how can I see the Test Suite which was used to execute the test?
回答1:
Have a look at following code snippet.
It shows you how to get Test Results for a specific Test Suite using Test Points Ids.
You can use similar approach to achieve your goal.
var tfsCollection = new TfsTeamProjectCollection(
new Uri(tfsUrl),
new System.Net.NetworkCredential(<user>, <password>));
tfsCollection.EnsureAuthenticated();
var testManagementService = tfsCollection.GetService<ITestManagementService>();
var teamProject = testManagementService.GetTeamProject(projectName);
var testPlan = teamProject.TestPlans.Find(testPlanId);
// Get all Test Cases belonging to a particular Test Suite.
// (If you are using several Test Configurations and want to take only one of them into account,
// you will have to add 'AND ConfigurationId = <your Test Configuration Id>' to the WHERE clause.)
string queryForTestPointsForSpecificTestSuite = string.Format("SELECT * FROM TestPoint WHERE SuiteId = {0}", suiteId );
var testPoints = testPlan.QueryTestPoints(queryForTestPointsForSpecificTestSuite);
// We are going to use these ids when analyzing Test Results
List<int> testPointsIds = (from testPoint in testPoints select testPoint.Id).ToList();
var testResults = teamProject.TestResults.ByTestId(testCaseId);
var testResultsForSpecificTestSuite = testResults.Where(testResult => testPointsIds.Contains(testResult.TestPointId));
This blog post will help you when creating queries: WIQL for Test
来源:https://stackoverflow.com/questions/21732992/show-test-result-form-test-suites-using-tfs-api