How to: Configure Test Deployment

The test engine for Visual Studio Ultimate can run tests either in the folder in which you have created or generated them or in a separate deployment folder. If you deploy your tests to a separate folder, you can continue to build your solution while your tests are running.

The following files and folders are copied to the deployment folder before the tests are run:

  • The test assembly file

  • All dependent assemblies

  • Files that you have specified, such as XML files and configuration files, on which tests depend. You can configure deployment both by specifying additional deployment items to be copied and by changing the deployment folder.

The deployment folder can be either local or remote. Remote test deployment occurs when you work with test agent controllers and test agents. For more information about remote deployment, see How to: Run a Test Using Test Controllers and Test Agents.

When you run the tests of a solution, Visual Studio creates deployment files under a folder named TestResults within the solution hierarchy. If the TestResults folder does not exist, Visual Studio creates it.


If you are using the Visual Studio IDE, this folder is created directly under the solution folder; if you are not using the Visual Studio IDE, the TestResults folder is created under the current folder.

Every time that you start a test run, Visual Studio creates, under the TestResults folder, a set of folders to be used exclusively for that test run. In the example shown in the following illustration, the first folder under TestResults is "<user name>@<computer name><date> <time>". This is the pattern used to name each of these folders.

Local Deployment Folder for Tests

Deployment folders for a local test run

As shown in the previous illustration, the solution ClassLibrary1 contains two projects, ClassLibary1 and TestProject1. Because tests have been run, this solution also contains a folder named TestResults. The TestResults folder contains one test results file for each test run. This test results file has the extension .trx.

Other folders are created under the TestResults folder, as described here:

  • Test run folder. Directly under TestResults is one folder for each test run that has been started. The test run folder has the same name as the test run, as displayed in the Test Results window and the Test Runs window. The default format for test run name is <user name>@<computer name> <date> <time>. The test run folder also contains the cleanup scripts that are run before and after tests are run.

  • Out folder and subfolders. Each test run folder contains a folder named Out. The Out folder is the actual deployment folder. Assemblies and other files or folders that are required for the test run are copied to the <solution>\TestResults\<test run>\Out folder every time that a test run is started.

  • In folder and subfolders. Each test run folder contains a folder named In. When certain test results are produced, they are stored in the In folder or a subfolder. For example, code-coverage results are stored in a file that is named data.coverage in a subfolder with the same name as the <test run id>\<computer on which tests were run>.

Setting deployment options

You can control test deployment in the following ways:

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. You can add files and folders to be deployed in your test settings file. For the steps to do this, see Create Test Settings to Run Automated Tests from Visual Studio or Create Test Settings for Automated Tests as Part of a Test Plan.

  • For information about the order in which deployment items are copied, see Deployment Order.

Select Deployment Items for a Single Test

The following procedures apply to only one test method. They determine which files Visual Studio Ultimate copies before it runs that specific test.

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.


    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.


    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.

  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#:



    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


    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 your test settings are copied later than items specified for an individual test.

The following list is ordered from highest priority to lowest. That is, items that are listed first will overwrite items that are 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.


    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 your test settings.

  3. Items specified in your test settings.

  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


Create Test Settings to Run Automated Tests from Visual Studio




Instrumenting and Re-Signing Assemblies