Aracılığıyla paylaş


How to: Configure Test Deployment

The test engine can run tests either in the folder in which you have created or generated them or in a separate deployment folder. For more information, see Test Deployment Overview.

The deployment folder can be local or remote. Remote test deployment occurs when you work with controllers and agents; for more information about remote deployment, see Controllers, Agents, and Rigs.

Setting Deployment Options

You can control test deployment in the following ways:

  • Turn deployment on or off. You can choose whether to enable or disable deployment; that is, whether to run tests in a deployment folder or in place. For more information, see Enable and Disable Test Deployment.

    Note

    If you are working with smart device tests, enable test deployment. Smart device tests are not run if deployment is disabled.

  • Select deployment items. For local test deployment, the test engine copies deployment items, both files and folders, to a folder on your computer before it runs tests. For information about the order in which deployment items are copied, see Deployment Order. For information about the ways to select additional deployment items to be copied. See Select Deployment Items.

Enable and Disable Test Deployment

By default, test deployment is enabled. You can change this setting in the test run configuration dialog box, as described in the following procedures.

To enable test deployment

  1. In Solution Explorer, under Solution Items, double-click the run configuration file that you want to edit.

    A dialog box that has a name such as <run config file name>.testrunconfig appears.

  2. Click Deployment.

  3. Select the Enable deployment check box.

    This change enables deployment only for the current test run configuration.

To disable test deployment

  1. In Solution Explorer, under Solution Items, double-click the run configuration file that you want to edit.

    A dialog box that has a name such as <run config file name>.testrunconfig appears.

  2. Click Deployment.

  3. Clear the Enable deployment check box.

    Please note the following about making this choice:

    • This change disables deployment only for the current test run configuration.

    • This setting controls both sides of test deployment: the deployment of actual tests and the deployment of items that you can specify. For more information about all facets of test deployment, see Test Deployment Overview.

    • If you are working with smart device tests, do not disable test deployment. Smart device tests are not run if deployment is disabled.

    • Disabling deployment also disables the gathering of code coverage data. To be able to gather code coverage data in your test runs, you must first re-enable test deployment.

Select Deployment Items

The following procedures, in which you determine files or folders to be copied, differ in scope. The first procedure sets deployment items for a run configuration. These items will be copied whenever that run configuration is active. The second and third procedures apply to only one test method; they determine which files Visual Studio Team System Test Edition copies before it runs that specific test.

To select files or folders to deploy, in run configuration

  1. In Solution Explorer, under Solution Items, double-click the run configuration file that you want to edit.

    A dialog box that has a name such as <run config file name>.testrunconfig appears.

  2. Click Deployment.

  3. Under Additional files or directories to deploy, specify additional files or folders to be copied. To do this, click Add file to select files; this opens the Add Deployment Files dialog box. You can also click Add Directory to select folders by using the Add Deployment Directory dialog box.

  4. In the .testrunconfig dialog box, click Save and then click OK.

    These deployment items will be copied to the deployment folder whenever this run configuration file is active.

To deploy items for a single test using the Deployment Items property

  1. Select a test in the Test View window or in the Test List Editor.

  2. Press F4.

    The Properties window for that test is displayed.

  3. Click the Deployment Items property.

    An ellipsis (…) appears in the value column.

  4. Click the ellipsis.

    The String Collection Editor dialog box is displayed.

  5. Before the test is run, type a path to a folder or a file that you want to have copied to the test deployment folder. Press Enter and type additional paths to specify additional folders and files to be deployed.

    Note

    You can use environment variables in paths for deployment items. For an example, see DeploymentItemAttribute.

  6. Click OK.

    The deployment items that you specified will be deployed in addition to those specified in the run configuration being used for the test.

    Note

    For unit tests, code that specifies these deployment items is written into the source code for the test, in the DeploymentItem attribute.

To deploy items for a single test using the DeploymentItem attribute

  1. Open the source-code file that contains a unit test. For more information, see How to: Create and Run a Unit Test.

  2. Under the TestMethod attribute, add a DeploymentItem attribute.

  3. For the parameter of the DeploymentItem attribute, specify the folder or file that you want to deploy for this test. You can use either an absolute path or a relative path. Relative paths are relative to the RelativePathRoot setting found in the .testrunconfig file.

    Example in C#:

    [TestMethod]

    [DeploymentItem("MyTestProject\\testdatasource.mdb")]

    public void TestMethod1()

    {

    // TODO: Add test logic here

    }

    Example in Visual Basic:

    <TestMethod()> _

    <DeploymentItem("MyTestProject\\testdatasource.mdb")> _

    Public Sub TestMethod1()

    ' TODO: Add test logic here

    End Sub

    Note

    You can use the DeploymentItem attribute only on test methods, not on test classes.

  4. Save and close the unit test source-code file.

    When you run the test, the deployment items that you specified will be deployed in addition to those specified in the run configuration being used for the test.

Deployment Order

Deployment items are copied in a specific order. Deployment items that are copied later overwrite those that were copied earlier, if they have the same name. For example, deployment items specified in run configuration are copied later than items specified for an individual test.

The following list is ordered from highest priority to lowest. That is, items listed first will overwrite items listed later. In the following list, certain items are deployed automatically to the deployment folder; these include the test assembly, instrumented binaries, and dependent assemblies.

  1. The file or files that comprise the test. These include test assemblies, for unit tests; text or .mht files, for manual tests; or other types of files for other test types, such as generic tests.

  2. Instrumented binaries. These are binary files that have been instrumented, for example, to enable code coverage.

    Note

    If you are using in-place instrumentation, binaries are instrumented first and then copied to the deployment directory; otherwise, they are copied first and then instrumented. In-place instrumentation is the default setting for tests that are run locally; you can change this setting in run configuration.

  3. Items specified in run configuration.

  4. Dependencies, for example, application configuration files and dependent assemblies.

  5. Per-test deployment items. These include items specified for the test method.

See Also

Tasks

How to: Configure Test Project Creation

How to: Configure the Dialog Boxes of Test Edition

Concepts

Test Deployment Overview

Controllers, Agents, and Rigs

Instrumenting and Re-Signing Assemblies

Reference

DeploymentItemAttribute

Other Resources

Configuring Test Execution