How to: Create a Host Adapter

Your host adapter is called by the agent that runs your tests. Once, at the beginning of a test run, the agent initializes the host adapter. Then, for every test in the test run, the agent calls the host adapter's ITestAdapter.Run method. When the test run is finished, the agent calls ITestAdapter.PreTestRunFinished. Finally, the agent calls ITestAdapter.Cleanup.

Inside the host adapter, these calls can be passed to the actual test adapters to run corresponding tests. The developer of the host adapter decides whether to pass these calls and when. It is recommended that the host adapter simulate the way the agent interacts with test adapters so that tests are run in a consistent way.

Follow the steps in this procedure to create a host adapter. Then follow the steps in How to: Install a Host Adapter to register and install it.

To implement a host adapter

  1. Implement the Microsoft.VisualStudio.TestTools.TestAdapter.ITestAdapter interface.

    You can find this interface in the assembly Microsoft.VisualStudio.QualityTools.ExecutionCommon.dll. After you implement ITestAdapter, in the ITestAdapter.Run method, you obtain the ITestElement interface.

  2. Call ITestElement.Adapter to obtain the adapter string for this test.

    The string has the same format as the registry entries under HostTypes: <type name>,<assembly name>.

  3. Use the adapter string to instantiate the test adapter and then call its Run method. You can do this by using CreateInstance.

  4. (Optional) To add a page for this host adapter to the run configuration editor, implement the IRunConfigurationCustomHostEditor interface.

    You can find this interface in the assembly Microsoft.VisualStudio.QualityTools.Vsip.dll. This should be a class derived from the UserControl class. This adds a page to the test run configuration dialog box of the Visual Studio UI. Test users can then use that page to specify a host adapter by configuring their test runs.

    This can be an empty implementation except for the host type name: IRunConfigurationCustomHostEditor.HostType.

    Note

    You can implement these two interfaces (ITestAdapter and IRunConfigurationCustomHostEditor) in one DLL or in two DLLs. By implementing them in separate DLLs, you can separate UI from execution. This is especially useful for running test runs remotely because agent computers do not typically have UI components installed.

See Also

Tasks

How to: Install a Host Adapter

Reference

IRunConfigurationCustomHostEditor