Show Test result Form test suites using TFS api

偶尔善良 提交于 2020-01-11 05:36:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!