Partager via


How to: Run Unit Tests Faster Using a Computer with Multiple CPUs or Cores

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

If you have a computer that has multiple CPUs or a single CPU with multiple cores, you can run unit tests in parallel to speed up your test execution time by using the capacity of the computer.

You can only use this parallel execution feature if the following conditions are true:

  • You run your tests on a computer that is using Microsoft Visual Studio 11 Developer Preview. The tests can be run locally or remotely using a test controller.

  • You only run unit tests. (The test cannot be an extension of a unit test type, for example coded UI tests.)

  • Your unit tests are thread-safe to prevent issues when the tests run in parallel.

  • You cannot collect any data and diagnostics with your test settings because this will slow down the test execution time and the data would be based on multiple tests running at the same time.

  • You must not run your unit tests as hosted tests. For example, you cannot use an ASP.NET host adapter.

    Note

    To improve performance when you use this feature, you must run the tests in parallel on a computer that has multiple CPUs or multiple cores. However, you can use this feature on a computer that has only a single CPU or a single core to verify that your tests can run in parallel.

Use the following procedure to modify your test settings to run your unit tests in parallel on your computer.

To run unit tests in parallel using multiple CPUs or multiple cores

  1. To open the solution that contains the unit tests that you want to run in parallel, click File, point to Open, and then click Project/Solution.

    The Open Project dialog box is displayed.

  2. Select your solution, and then click Open.

  3. To modify the test settings file, open Solution Items, right-click the test settings file, and point to Open With. Select an editor.

    The file is displayed in the editor.

  4. To set the unit tests to run in parallel, add the parallelTestCount attribute to the Execution element as shown in the following example:

    <Execution parallelTestCount="0">
    

    The values for this attribute are defined in the following table:

    Value for parallelTestCount

    Description

    Not specified

    (Default) 1 CPU/Core is used

    0

    Unit tests are run in parallel based on your CPU and core count

    n

    Run n tests in parallel at a time, where n represents a given number. (Use this if you do not want to use all your CPUs or cores when you run your tests in parallel.)

  5. Save the test settings file and run your tests locally on your computer from Microsoft Visual Studio 11 Developer Preview.

    Your tests are displayed in the Test Results window when they run. You should see that multiple tests are running at the same time.

See Also

Concepts

How to: Create and Run a Unit Test