To use TFS Test Suites via code, you should first create TFS Collection and Team Test Project. You can find more information in my previous post: How to: Connect to TFS Team Project C# Code.
Next you need to connect to a specific test plan. You can read more in the article: Manage TFS Test Plans C# Code.
In MS Test Manager, you can edit, create, delete test suites. Here I will show you how to do these actions via C# code.
There are three types of test suites- static, requirement-based and query-based. You can add child suites only to the first type. The current tutorial is only applicable for the static test suites.
Get All TFS Test Suites
Our first job is to create a wrapper class for the TFS Suite (ITestSuiteBase). It will contain only the most important properties of the base core TFS suite object and will be serializable because the standard MS objects are not. This means that you cannot use them in web services or put them into the clipboard.
You need the following three methods to get a tree based list of all static test suites in the specified test plan.
testPlan.RootSuite.SubSuites gives you all first level test suites in the test plan. Next we use recursion to get all child test suites. You need to refresh every item because otherwise you will not get the last screenshot of the test suites, TFS sometimes caches the query results. Every custom suite entity contains the list of its childs and reference to its parent.
Add New TFS Test Suite
First we initialize the parent test suite if it is not the static suite we stop the process. If the parent suite is not found, we add the new test suite to the entries of the root test plan suite. To complete the process, we need to save the test plan.
Delete TFS Test Suite
If the parent is not found we remove the test suite from the test plan suites. Again to complete the process we need to save the test plan.