Team Foundation Server-Microsoft Test Manager Extensibility

The TFS-MTM Extensibility feature offers you, by means of TestArchitect-supported API methods, the ability to extend and customize the environment for executing automated test cases.

As one example, you may customize TFS-MTM to allow a given test run to include test cases distributed across multiple repositories. The supported API methods are all declared in the TAIntegrationExtensibility class, generated during TA-MTM project creation.

TAIntegrationExtensibility class

The TAIntegrationExtensibility class provides template methods required for writing extensibility code for TFS-MTM.

The TAIntegrationExtensibility class is generated in the Solution Explorer tree of your Visual Studio project once you create a TA-MTM project.

Important: If you created a TA-MTM project in earlier versions of TestArchitect – that is, prior to version 8.2 Update 3 – your project does not contain the TAIntegrationExtensibility class. In order to have this class included in your project, you must upgrade the build assemblies of the TA plug-in. Once the project is successfully upgraded, the TAIntegrationExtensibility class is available for editing.

Supported extensibility methods offered by TAIntegrationExtensibility.cs

The following table lists the extensibility methods exposed by the TAIntegrationExtensibility.cs class.
Method Order of invocation
ClassInitializing() When applied, this method is invoked before execution of the ClassInitialize() method.*
ClassInitialized() When applied, this method is invoked after execution of the ClassInitialize() method.*
ClassCleaning() When applied, this method is invoked before execution of the ClassCleanup() method.*
ClassCleaned() When applied, this method is invoked after execution of the ClassCleanup() method.*
TestInitializing() When applied, this method is invoked before execution of the TestInitialize() method.*
TestInitialized() When applied, this method is invoked after execution of the TestInitialize() method.*
TestCleaning() When applied, this method is invoked before execution of the TestCleanup() method.*
TestCleaned() When applied, this method is invoked after execution of the TestCleanup() method.*
RunTestCaseInitialize() When applied, this method is invoked before execution of the RunTestCase() method.*
RunTestCaseCleanup() When applied, this method is invoked after execution of the RunTestCase() method.*
AssemblyInitializing() When applied, this method is invoked before execution of the AssemblyInitialize() method.*
AssemblyInitialized() When applied, this method is invoked after execution of the AssemblyInitialize() method.*
AssemblyCleaning() When applied, this method is invoked before execution of the AssemblyCleanup() method.*
AssemblyCleaned() When applied, this method is invoked after execution of the AssemblyCleanup() method.*
Note: * ClassInitialize(), ClassCleanup(), TestInitialize(), TestCleanup(), RunTestCase(), AssemblyInitialize(), and AssemblyCleanup() are all built-in methods, and are generated once you successfully associate TestArchitect test cases with TFS test cases (Learn more.)

How to declare customized extensibility methods

All the customized extensibility methods above must be declared within the TAIntegrationExtensibility class in accordance with the Attribute Method technique.(Learn more.)

Tip: By default, some of the supported extensibility methods above, such as ClassInitialized(), ClassCleaning(), and TestInitialized(), are automatically generated in advance in the TAIntegrationExtensibility class, for your ease of use.
The following example depicts declarations of two methods:
  • the extensibility ClassInitialized() method. Any code appearing within the curly brackets is invoked right after the ClassInitialize() method is executed, and
  • the extensibility ClassCleaning() method. Any code appearing within the curly brackets is invoked right before the ClassCleanup() method is executed.
/// <summary>
/// Code to be run after ClassInitialize
/// </summary>        
[TAExtensibilityMethod(LoaderConstant.ClassInitialized)]
 public void ClassInitialized(TAExecutionArguments args)
{
   //Code implementation						
}


/// <summary>
/// Code to be run before ClassCleanup
/// </summary>
[TAExtensibilityMethod(LoaderConstant.ClassCleaning)]
public void ClassCleaning(TAExecutionArguments args)
{
    //Code implementation
}

Supported API methods in ITAExecution.cs

The following table lists API methods of the ITAExecution.cs class. This interface contains behaviors that are invoked to get or set execution information of TA.

Name Description Parameter Returned value
ExecutionInfo() Get or set the current test execution environment.
A collection of key/value pairs:
  • Key: Name of the execution parameter in the dictionary.
  • Value: Value of the parameter in the dictionary.
A dictionary containing all specified settings for the execution environment.
Save() Save the execution environment. None
  • 1 if successful;
  • 0 if unsuccessful.
FormatResultFilterString() List of result types to be uploaded A comma-delimited list of TestResultType arguments. {passed, failed, etc.} A formatted string used for selecting results to be uploaded.

Supported constant values in TAExecutionConstant.cs

The following table lists constant values of the TAExecutionConstant.cs class. This class contains the constants that are used for the TAExecution object.

Name Description
LicenseServer License server hostname or IP address
LicensePort License server port
TrialKey License trial key
RepositoryServer Repository server hostname or IP address
RepositoryName Repository name
RepositoryPort Repository port
UserName Repository user name to log in with
Password Password to log in with
ProjectName Project name
Keyword Keyword variation(s)
Version AUT version(s)
RemoteMode
  • Remote execution mode?
  • Possible values:
    • Yes or
    • No.
RemoteHost Remote hostname or IP address
RemoteHostPort Remote host port
AddResultMode
  • Automatically add result(s) to repository? (Learn more.)
  • Possible values:
    • Yes or
    • No
ResultRepository Destination on repository to store test results to. (Learn more.)
ByResultMode
  • Limit the types of test results stored to the repository? (Learn more.)
  • Possible values:
    • Yes or
    • No
ByResult
  • List of result types to add to the repository. (Learn more.)
  • Possible values:
    • Passed,
    • Passed with Warnings/Errors,
    • Failed, or
    • Passed with known bug
Tip: Use commas (,) as delimiters between possible values.
TFSUploadResultMode
  • Upload attachment(s) to TFS? (Learn more.)
  • Possible values:
    • Yes or
    • No
TFSUploadResultType
  • List of TFS test result type(s) that accept the attachment. (Learn more.)
  • Possible values:
    • Passed,
    • Failed, or
    • Inconclusive
Tip: Use commas (,) as delimiters between possible values.
TFSUploadAttachmentType
  • Format for test result to be added to TFS. (Learn more.)
  • Possible values:
    • HTML,
    • ZIP, or
    • AUTO.
    Note: The AUTO option uploads the result as a ZIP file if the file exceeds a given size, specified in the TFSUploadAttachmentAutoZipSize constant below. Otherwise, the result is uploaded as an HTML file.
TFSUploadAttachmentAutoZipSize Minimum size of test results to be compressed as ZIP automatically. (Learn more.)
StartupSettingsMode
  • Enable startup setting? (Learn more.)
  • Possible values:
    • Yes or
    • No.
StartupSettings List of startup setting(s). (Learn more.)

Example

Suppose that we'd like to implement the extensibility ClassInitialized() method, which is invoked after execution of a ClassInitialize().
[TAExtensibilityMethod(LoaderConstant.ClassInitialized)]
 public void ClassInitialized(TAExecutionArguments args)
{
   //Code implementation						
}
In the implementation code of ClassInitialized(), we first provide values for several TA constants, such as RepositoryServer, RepositoryName, RepositoryPort, ProjectName, UserName, and Password. Your snippet of code may resemble the following:
execObj.ExecutionInfo[TAExecutionConstant.RepositoryServer] = "localhost";
execObj.ExecutionInfo[TAExecutionConstant.RepositoryName] = "SampleRepository";
execObj.ExecutionInfo[TAExecutionConstant.RepositoryPort] = "53400";
execObj.ExecutionInfo[TAExecutionConstant.ProjectName] = "Car Rental";
execObj.ExecutionInfo[TAExecutionConstant.UserName] = "administrator";
execObj.ExecutionInfo[TAExecutionConstant.Password] = "";
Additionally, we enable startup settings in code, and then define a list of startup settings to be invoked. In this case, we define:
  • use browser built-in setting:
    • Default value: chrome
    • Description: default browser
  • path user-defined setting:
    • Default value: D:\Sample.exe
    • Description: AUT path
Your snippet of code may resemble the following:
List<StartupSetting> listStartupSettings = new List<StartupSetting>();

StartupSetting browser = new StartupSetting("use browser", "chrome", "default browser", StartupSettingType.BUILT_IN_SETTING);
StartupSetting AUT = new StartupSetting("path", "D:\Sample.exe", "AUT path", StartupSettingType.USER_DEFINE_SETTING);

listStartupSettings.Add(browser);
listStartupSettings.Add(AUT);

execObj.ExecutionInfo[TAExecutionConstant.StartupSettings] = listStartupSettings;
execObj.ExecutionInfo[TAExecutionConstant.StartupSettingsMode] = "yes";

Ultimately, the final code to implement the extensibility ClassInitialized() method may resemble the following:

/// <summary>
/// code to be run after TestInitialize
/// </summary>
         
[TAExtensibilityMethod(LoaderConstant.TestInitialized)]
         
public void TestInitialized(TAExecutionArguments e)
{
   ITAExecution execObj = TAIntegrationLoader.Instance.ITAExecution;
         
   execObj.ExecutionInfo[TAExecutionConstant.RepositoryServer] = "localhost";
   execObj.ExecutionInfo[TAExecutionConstant.RepositoryName] = "SampleRepository";
   execObj.ExecutionInfo[TAExecutionConstant.RepositoryPort] = "53400";
   execObj.ExecutionInfo[TAExecutionConstant.ProjectName] = "Car Rental";
   execObj.ExecutionInfo[TAExecutionConstant.UserName] = "administrator";
   execObj.ExecutionInfo[TAExecutionConstant.Password] = "";
         
   List<StartupSetting> listStartupSettings = new List<StartupSetting>();
         
   StartupSetting browser = new StartupSetting("use browser", "chrome", "default browser", StartupSettingType.BUILT_IN_SETTING);
   StartupSetting AUT = new StartupSetting("path", "D:\Sample.exe", "AUT path", StartupSettingType.USER_DEFINE_SETTING);
         
   listStartupSettings.Add(browser);
   listStartupSettings.Add(AUT);
         
   execObj.ExecutionInfo[TAExecutionConstant.StartupSettings] = listStartupSettings;
   execObj.ExecutionInfo[TAExecutionConstant.StartupSettingsMode] = "yes";
         
   execObj.Save();
}