Search code examples
tfstfs-sdk

Remove/Delete TestSuite from TFS2012 programmatically with API


I am using the API from TFS2012 to automatically create Testsuites in our tfs. This is all going great. But I want to remove all the TestSuites from tfs before adding them through the API.

Does anyone know if the API provides this functionality.

Thank you.


Solution

  • Do the following, where tfsUri is the location of the collection, and tfsProjectName is the name of the project:

    var tfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
    var tfsTestManagementService = tfsTeamProjectCollection.GetService<ITestManagementService>();
    var tfsTestManagementTeamProject = tfsTestManagementService.GetTeamProject(tfsProjectName);
    var tfsTestPlans = tfsTestManagementTeamProject.TestPlans.Query("SELECT * FROM TestPlan");
    foreach (var tfsTestPlan in tfsTestPlans)
    {
        tfsTestPlan.Delete(DeleteAction.ForceDeletion);
    }