Share via

Overview of Host Adapters

To run tests inside a process other than VSTestHost.exe, you typically need to implement a host adapter. A host adapter is a software component that lets you run tests in a specific environment. This hosting environment may be a specific process such as Microsoft SQL Server 2005 or a process with particular traits such as limited security or custom environment variables. For more information, see Running Tests in Application Hosts.

Any test type can be hosted if the SupportedHostAdapters and SupportedTestTypes registry keys are set correctly on the client computer. For more information, see Configuring Host Adapters and Test Types.

In Team Edition for Testers, you can set properties on a test to determine the host adapter that will be used when you run the test. You can also set the host adapter for all tests in a test run by selecting the host adapter in the test run configuration editor. The host adapter selected for an individual test overrides the setting for a test run.

You could also use a host adapter to run tests of a third-party test type. For information about how to create new test types, see Creating Custom Test Types in Visual Studio.

Component Interaction and Sequence of Events

The following diagram shows how the various components interact in one typical host-adapter usage.


In the case shown here, the agent is running remotely. That is, the agent is running on a computer other than that of the Visual Studio 2008 IDE. This does not always have to be the case; with local test runs, the agent runs on the local computer, in the VSTestHost.exe process.

Host Adapter Sequence

When you run tests that use a host adapter, the following sequence of events occurs:

  1. The test agent process initializes the agent-side component of the host adapter. Then, for each test in the list of tests to run, the test agent calls the agent-side component of the host adapter.

  2. The agent-side component of the host adapter first starts the host, if necessary, and then it instantiates the host-side component of host adapter.

  3. On the host side, the test execution component (ITestAdapter.Run on the host side) is called with the ITestElement and ITestContext passed from the agent-side host adapter. The host-side host adapter loads the test adapter for the test and runs the test.

  4. The test adapter returns test results to the agent through IResultSink. After the last test has finished running, the agent can call ITestAdapter.Cleanup.


    During this sequence, the agent calls ITestAdapter.Initialize and ITestAdapter.Cleanup on Host Adapter only one time each but it calls ITestAdapter.Run for every test in the test run.

Host Adapters and Test Adapters

As shown in the diagram in the previous section, you must have both a host adapter and a test adapter to run tests in a particular environment. These two components differ in important ways:

  • A host adapter provides a flexible way to run other test adapters.

  • A test adapter is specific to a test type, whereas a host adapter is specific to a host in which tests are run, such as a process.

  • When the agent uses a host adapter, it does not also instantiate test adapters for hosted tests. Instead, the agent instantiates only the host adapter and then works through it by calling methods of the ITestAdapter interface. It is the responsibility of host adapter to instantiate test adapters for hosted tests.

See Also


How to: Create a Host Adapter

How to: Install a Host Adapter


Running Tests in Application Hosts