Share via


How to: Specify Tests to Run in a Host Adapter

Testers can specify tests to run in a host in either of two ways:

  • In the Properties window, specify the host type to use when you run the test. For unit tests, you can also set the host type as one of the parameters of the HostType attribute. For more information, see Use the HostType Attribute.

  • Choose the host on the Hosts page in the test run configuration editor. For each custom host, the name under Host type on the Hosts page matches the string that is returned by HostType. For more information, see Use the Run Configuration Editor.

Use the property setting and the HostType attribute to choose individual tests to run on a particular host. Use the test run configuration editor to run all the tests in a test run in a certain way, such as on a particular host. For more information about how to use the test run configuration editor, see Configuring Test Execution.

The host that is specified as a property or in the HostType attribute might differ from the host that is 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

Use the Run Configuration Editor

To run tests on a specific host by using the run configuration editor

  1. 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.

  2. Click Hosts.

    Under Host type, the names of all built-in and custom hosts are displayed.

  3. Select the host to use for your tests.

  4. If additional options are displayed on the Hosts page for this host, set them as your test runs require.

  5. (Optional) Determine whether to run tests by using the default host as an alternative if your selected host adapter is not available. Under For tests not hostable by specified host adapters, click Run in default host if you want tests to run in the default host, VSTestHost.exe, when your selected host adapter is not available. If you do not want Visual Studio to run tests when the selected host adapter is not available, select Do not run. In this case, the tests produce the result Not Runnable. 

  6. Click Save As.

    The Save As dialog box appears.

  7. For File Name, type a name that identifies this test run configuration as the one to use for running tests on the specified host.

  8. Click Close.

  9. 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.

  10. 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.

See Also

Tasks

How to: Create a Host Adapter

How to: Install a Host Adapter

Other Resources

Microsoft.VisualStudio.TestTools.UnitTesting.HostTypeAttribute.HostType

Configuring Test Execution