How to: Specify Tests to Run in a Host Adapter
Testers can specify tests to run in a host in either of two ways:
Specify the host as one of the parameters of the HostType attribute for the test. For more information, see.
Choose the host on the Hosts page in the test run configuration editor. This editor is displayed only if the author of the host adapter has implemented theinterface, as described in . For each custom host, the name under Host type on the Hosts page matches the string that is returned by . For more information, see .
Use the HostType attribute to choose individual tests to run on a particular host. Use the test run configuration editor to run all of the tests in a test run in a certain way, such as on a particular host. For more information about using the test run configuration editor, see Configuring Test Execution.
The host specified in the HostType attribute might differ from the host specified in the current test run configuration. In this case, the following rules are followed:
If the test run configuration indicates to use the default test host and a HostType is specified, the host indicated by the HostType is used.
If the test run configuration indicates a test host other than the default test host, that host is used regardless of any HostType specification. This lets testers and developers specify the test host to use even if they cannot recompile the test assembly.
Use the HostType Attribute
To configure a test to run on a specific host by using the HostType attribute
To configure a unit test to run on a specific host, specify the host adapter in the HostType attribute of that test. The HostType attribute in the following example configure a test to run in ASP.NET:
For unit tests, use the Microsoft.VisualStudio.TestTools.UnitTesting.HostTypeAttribute.HostType attribute from the Unit Testing Framework. For custom tests, use the HostType attribute from the IHostedTest interface in the namespace.
Use the Run Configuration Editor
To run tests on a specific host by using the run configuration editor
Under the Solution Items folder in Solution Explorer, double-click the test run configuration file that you want to open.
- or -
Point to Edit Test Run Configurations on the Test menu and then click a run configuration on the submenu.
The run configuration opens for editing.
Under Host type, the names of all built-in and custom hosts are displayed.
Select the host to use for your tests.
If additional options are displayed on the Hosts page for this host, set them as your test runs require.
Click Save As.
The Save As dialog box appears.
For File Name, type a name that identifies this test run configuration as the one to use for running tests on the specified host.
On the Test menu, point to Select Active Test Run Configuration.
A submenu lists all the test run configurations in your current solution or project.
To start the test run configuration that is configured to run tests under your host, click it.
That run configuration will now apply when you run tests.