Restore deleted test suite from backup database

In this post, I am going to talk about how to restore a deleted test suite. For deleting a test suite, a user needs to have manage test plan permission on the area path of the test plan. This is quite restrictive permission but still we have heard numerous instances where users have deleted the suites knowingly/unknowingly which have caused data loss for an organization. We don't have an automated way to restore deleted suites . You can restore it manually though by creating a replica of the deleted suite if you have a back up copy of the TFS database (both configuration and project collection) which contains the deleted test suite. Normally almost all the companies enforce to take backups so finding a backup having the deleted suite should not be very difficult.

Note: Querying or modifying SQL tables directly is not a supported option and can change in future versions. Steps mentioned below are provided “as-is” to help in identifying the deleted suites and recovering the deleted data from backups.

Now let us go through the steps you should perform to recover your deleted suite.

  • Identify the deleted suites: -  All the list of deleted test suites can be retrieved by running following query on project collection database:

Select * from tbl_auditlog where ObjectType = 11

Sample output- --

PartitionId AuditId DateModified Action ObjectType ObjectID1 ObjectID2 ProjectId AuditIdentity

Over here DateModfied represents the date of deletion, ObjectID1 represents the deleted test suite Id and AuditIdentity is the TFS identity of user who deleted the suite.

For finding more information about the user who deleted the suite, run the following query on TFS configuration database

select * from tbl_Identity where Id = 'AuditIdentity' 

You can also find deleted suites by following the steps mentioned here.

  • Find the backup database and attach it to SQL Server: -  

Since this test suite is deleted, current database would not hold any information of this suite. You need to find out the latest back up database in which the test suite was present. You already know the date of deletion of test suite, so pick up a database which was backed up just before the deletion date of suite.

  • Find basic information about deleted suite from backup & create the new one using MTM: -

          Get basic information of test suite like ProjectName, TestPlanId, ParentSuiteId, Title, SuiteType, Query, RequirementId from the backup database using this SQL query:

select p.ProjectName, s.*
from tbl_suite s
join  tbl_Project p
on s.ProjectId = p.ProjectId
where s.SuiteId = @deletedSuiteId      -- deletedSuiteId is the identity of deleted suite

Now in Microsoft Test Manager, connect to the project having its name as ProjectName. Find the test plan with its id as TestPlanId and connect to it. ParentSuiteId refers to the identity of the suite under which new suite needs to be created.

Suites can be of three different types which are as follows:

Type 1 represents Query Based Suite.

Type 2 represents Static Suite

Type 3  represents Requirement Based Suite.

 If the Type is for Query Based Suite then create a query based suite. Set its query as Query and title as Title

 If the Type is for Requirement Based Suite then create a requirement based suite. Select a requirement with id as RequirementId.

 If the Type is for Static Suite, just create a new static suite and set its title as Title.

  • Find configuration of deleted suite from backup & assign them to new suite: -

Find the configuration of the deleted suite using the following query on backup database

select inheritConfigs
from tbl_suite w
here SuiteId = @deletedSuiteId

If inheritConfigs flag is 1 then just set "Inherit configurations from parent test suite" in Default Configurations window from Microsoft Test Manager otherwise we need to retrieve configurations for this test suite.You can retrieve them using the following query on backup database.

select c.* from tbl_SuiteConfiguration s
join tbl_Configuration c
on s.ConfigurationId = c.ConfigurationId
where s.SuiteId = @deletedSuiteId

Now apply the configurations using MTM on the newly created suite.

  •  Find the test cases associated with deleted suite from the backup and add them to new suite: -

Find the test cases associated with deleted suite by using the below SQL query on the backup database:

select e.TestCaseId
from tbl_SuiteEntry e
where e.SuiteId = @deletedSuiteId
and e.TestCaseId <> 0

Add these test cases to the new test suite using Microsoft Test Manager

 Note: - This step is not applicable for Query based suite.

  • Find the results associated with the deleted suite and bulk mark them in new suite: -

Find the test results associated with deleted test suite by using the below SQL query on the backup database

select c.Name, r.*
from tbl_TestResult r
join tbl_Point p
on r.TestPointId = p.PointId
 and r.TestRunId = p.LastTestRunId
 and r.TestResultId = p.LastTestResultId
join tbl_configuration c
on c.ConfigurationId = r.ConfigurationId
where p.SuiteId = @deletedSuiteId

The above query returns the last result for a given test case/configuration combination. Using the outcome field from for the above query, you should bulk mark the corresponding tests in your new suite. For example if OutCome value is 2 for a test case/configuration name , you should mark the corresponding test as passed.

Possible list of test outcome is as follows:

        None = 1,
        Passed = 2,
        Failed = 3,
        Inconclusive = 4,
        Timeout = 5,
        Aborted = 6,
        Blocked = 7,
        NotExecuted = 8,
        Warning = 9,
        Error = 10,
        NotApplicable = 11,
        Paused = 12,

Note: - This step is optional and is applicable only for manual test cases.

Congratulations !! You have restored your suite now. Enjoy !!

Comments (1)

  1. Charlie says:

    I was doing some exploration within Visual Studio 2013 Update 3 ALM Virtual Machine. I started to think about restore and backup of my MTM test artifacts. Obviously TFS stores all objects and backup can be used; however I was looking for granularity. The ability to easily delete a test suite and inability to easily recover it was a show stopper. I literally shut down the vm and packed up my laptop.

Skip to main content