Search code examples
tfs-2015data-cleaning

TFS Query or SQL Query to Identify Empty Test Plans or Empty Test Suites


We are fairly new to TFS and I have been trying to clean up some of the areas. I can see through a simple TFS query that there are over 180 Test Suites with the name "New suite"... I don't want to try to open each one and look to see if there are test cases assigned to it.

Is there a way to get a report of Empty Test Suites, and maybe Empty Test Plans?

Thanks

Pat


Solution

  • You can use REST API to Get a list of test suites, "testCaseCount" will be included in the response. See below example:

    GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/fabrikam-fiber-tfvc/_apis/test/plans/1/suites?api-version=1.0
    

    For more information please refer to https://www.visualstudio.com/en-us/docs/integrate/api/test/suites

    Besides, you can also get the empty Test Suites or Test Plans by running the sql query in SQL Server, see below sample.

      SELECT 
           [SuiteId]
          ,[PlanId]
          ,[ParentSuiteId]
          ,[Title]
          ,[TestCaseCountFromMtm]
          ,[TestCaseCountFromWeb]
    
      FROM [Tfs_CollectionLC].[dbo].[tbl_Suite]
    
      WHERE  [TestCaseCountFromMtm]='0' and [TestCaseCountFromWeb]='0'
    

    enter image description here

    Update:

    If you want to get the Plan and Parent Suite name, in above query the "Title" column will display all the suite name including the Parent Suite name. I didn't find the exact table to get the Plan name, but we can get it via REST API, you can use below sample PowerShell script to get all the Test Plan names. Just copy/paste the script and save it as .ps1 file to run on your client.

    $project = "TFVC-Scrum" # Change to your team project name here
    $baseUrl = "http://12r2:8080/tfs/CollectionLC"  # Change to your TFS Collection URL         
    $testplanUrl = "{0}/{1}/_apis/test/plans?api-version=1.0" -f $baseUrl, $project 
    $TestPlans = (Invoke-RestMethod -Uri $testplanUrl -Method Get -UseDefaultCredential).value
    
    $TestPlanResults = @()
    
    foreach($TestPlan in $TestPlans){
        $testplanitemUrl = "{0}/{1}/_apis/test/plans/{2}?api-version=1.0&includeDetails=true" -f $baseUrl,$project, $TestPlan.id
    
        $TestPlanItem = Invoke-RestMethod -Uri $testplanitemUrl -Method Get -UseDefaultCredential
    
        $customObject = new-object PSObject -property @{
              "TestPlanid"= $TestPlanItem.id
              "TestPlanName"= $TestPlanItem.name
            } 
    
        $TestPlanResults += $customObject       
    }
    
    $TestPlanResults | Select `
                    TestPlanid,
                    TestPlanName
    

    enter image description here