Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Test result Form test suites using TFS api

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?

like image 664
user1418385 Avatar asked Feb 12 '14 15:02

user1418385


People also ask

Can I export test results from Azure DevOps?

Yes. See Copy test cases. For Azure DevOps Server 2020 and later versions, you can copy test cases from within a project or another project to a test suite, or you can use the Grid view to copy and paste test cases from one suite to another. Optionally, you can bulk import and export test cases.

How are test suites and test cases connected?

A test case answers the question: What am I going to test? You develop test cases to define the things that you must validate to ensure that the system is working correctly and is built with a high level of quality. A test suite is a collection of test cases that are grouped for test execution purposes.

How do I copy a test suite from one test plan to another in TFS?

Open Test Plans>Test plans, and choose the test plan you want to copy from the Mine or All page. Select More actions, and choose the Copy test plan menu option. This option lets you copy or clone test plans within a project. Specify the name of the new test plan, and select an Area Path and Iteration Path for the plan.


1 Answers

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

like image 197
Elena Avatar answered Sep 29 '22 05:09

Elena