Show Test result Form test suites using TFS api
Asked Answered
P

1

5

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?

Pelerine answered 12/2, 2014 at 15:58 Comment(2)
I'm not entirely sure, since I haven't delved into this part of the API in recent days, but I remember that the ITestPoint/TestPointId actually links the test result to the test suite.Transversal
This blogpost might help you forward as well: blogs.msdn.com/b/densto/archive/2010/03/04/…Transversal
Y
9

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

Ypres answered 13/2, 2014 at 8:11 Comment(3)
I get nullpointerexception on testManagementService. Any Ideas why?Limonite
@Limonite Please provide more information. Do you mean you get a NullReference exception? When do you get it?Ypres
I fixed it, just incase someone has the same problem I forget to change the url from the base url to one of the collections and so it could not find the test management serviceLimonite

© 2022 - 2024 — McMap. All rights reserved.