Overview of the Host Adapter Sample
By default, tests are hosted, or run, in the VSTestHost.exe process. This sample demonstrates how to extend Visual Studio Team System testing tools by creating a custom host adapter that runs tests in a different environment, such as in the Visual Studio process.
The Host Adapter sample is useful in the following ways:
If you create Visual Studio packages or add-ins, you can use this sample to run unit tests on code that runs in the Visual Studio process. Because the Visual Studio process is not the default test environment, you will need a host adapter to run your unit tests in the same process as the code you are testing (your package or add-in).
You can use this sample to debug tests in the Visual Studio process. This means that your debugging experience is the same as that of debugging tests that are running in the VSTestHost.exe process.
The sample provides a stand-alone installer (MSI) with WiX (Windows Installer XML) source code that you can use to install and uninstall the host adapter.
For more information, see:
The ReadMe.doc file in the solution folder.
The Help topic Creating and Using Host Adapters.
The MSDN forum Visual Studio Team System - Testers.
The Microsoft Visual Studio Developer Center. This site is the download location for the Visual Studio SDK.
Getting Started
The Host Adapter sample provides the following C# projects. All projects except the Unit Test project are part of the solution VsIdeHostAdapter.sln:
HostAdapter.Implements both the agent side and the host side of the host adapter.
Framework.Provides the API for tests that run inside the Visual Studio process to get the DTE object of the Visual Studio automation object model, and Visual Studio services.
InstallHelper. Implements the custom install action by extending the System.Configuration.Install.Installer class. This project produces an object that is called when you install the sample by running the VsIdeTestHost.msi file.
Installer.Builds the installer, the VsIdeTestHost.msi file.
UnitTest. Contains unit tests that test the host adapter sample. To run unit tests, install the VsIdeTestHost.msi, restart Visual Studio, open UnitTest.sln, and run tests from Test View or Test Explorer. This project is part of its own solution, UnitTest.sln. For more information about how to run tests, see How to: Run Selected Tests.
To build the sample, open VsIdeTestHost.sln and build the solution. Building the sample creates the VsIdeTestHost.msi file in the Installer\Debug folder under the VsIdeHostAdapter solution folder.
Running Tests
For information about running tests in the Visual Studio process, see How How to: Run Tests in the Visual Studio Process.
List of Project Files
File Name |
Description |
---|---|
Framework\UIThreadInvoker.cs |
Contains the implementation for the UIThreadInvoker class. |
Framework\VsIdeTestHostContext.cs |
Contains the implementation for the VsIdeTestHostContext class. |
HostAdapter\AgentSide\VsIdeHostAdapter.cs |
Contains the implementation for the VsIdeHostAdapter class. |
HostAdapter\HostSide\HostAdapterHostSide.cs |
Contains the implementation for the HostAdapterHostSide class. |
HostAdapter\HostSide\RunConfigControl.cs |
Contains the implementation for the RunConfigControl class. |
HostAdapter\HostSide\RunConfigData.cs |
Contains the implementation for the RunConfigData class. |
HostAdapter\HostSide\VsDebugger.cs |
Contains the implementation for the VsDebugger class. |
HostAdapter\HostSide\VsIdeTestHostAddin.cs |
Contains the implementation for the VsIdeTestHostAddin class. |
InstallHelper\InstallHelper.cs |
Contains the implementation for the InstallHelper class. |
Installer\Installer.vcproj |
Makefile project used to build the installer file, VsIdeTestHost.msi. |
Installer\build.bat |
Contains batch commands to build the installer file, VsIdeTestHost.msi. |
Installer\VsIdeTestHost.AddIn |
Contains the information about the add-in for Visual Studio. |
Installer\VsIdeTestHost.wxs |
Contains WiX source code for the installer, VsIdeTestHost.msi. |
UnitTest\VsIdeHostAdapterTest.cs |
Contains unit tests for the host adapter. |
Unit Tests
The following unit tests are provided with this host adapter sample.
CheckInstallationRegistry. Checks VS IDE Host Adapter installation registry settings.
ContextDteSetStatusBarText. Test for VsIdeTestHostContext.Dte.
ContextServiceProvider. Test for VsIdeTestHostContext.ServiceProvider.
UIThreadInvokerOpenEmptySolution. Test for UIThreadInvoker.Invoke(delegate).
UIThreadInvokerWithArgs. Test for UIThreadInvoker.Invoke(delegate, args).