Run Unit Tests in Parallel using Visual Studio 2010

30/12/2010

Run Unit Tests in Parallel using Visual Studio 2010

Today almost each and every machine have multiple CPU’s or a CPU with multiple cores, so why not using them in order to speed up your tests runs and run more Tests in parallel.

In Visual Studio 2010 Microsoft added the ability to run Tests (Only for Unit Tests) in parallel.

  • Data Collectors cannot be enabled if using Parallel execution.
  • You must have multi-core/CPU machine

image

How To Enable Parallel Execution of Unit Tests

1. Create new Test Project in Visual Studio 2010

2. Right click on “Local.testsettings” and click “Open With”, choose “Xml (Text) Editor” and hit OK.

image

image

3. Expand the Execution Tag and add additional attribute called – parallelTestCount:

What’s are your options:

  • 0 = Auto configure: We will use as many tests as we can based on your CPU and core count
  • Define the number of tests to run in parallel – If you don’t want to use all cores/cpu’s

image

 

This is my code for that Demo:

image

As you can see from the picture below I have 4 unit tests running in parallel and another picture below you can see my computer finally working Smile

image

image

Enjoy

Add comment
facebook linkedin twitter email

Leave a Reply

6 comments

  1. Jim Calhoun04/01/2011 ב 01:59

    Question 0
    Does this work when using a controller agent, meaning can I run parallel on multiple agents?

    Question 1
    I read somewhere that when you have more than one agent, the first agent will take the first 100 tests, the second the next hundred, etc. If I have have 90 very long running tests, can I split them among 3 agents?

    Question 2. If I want to run all 90 tests on each agent (XP, Vista, 7) is there a way to do that?

  2. shair04/01/2011 ב 18:53

    Hi Jim,
    This will not work when using Agents.
    Both Question 1 and 2 are possible using Test Agenst and Load Test.

  3. tfs_test24/06/2013 ב 20:20

    I have only one Test Agent machine and I want to run parallel test on a single agent… Is it possible? IF yes then how 🙂 ?

    1. Shai Raiten
      Shai Raiten18/06/2014 ב 09:29

      Hi,
      Yes you can but just for Unit Tests not Coded UI.

  4. tfstest24/06/2013 ב 20:22

    I have only one Test Agent machine and I want to run parallel test on a single agent… Is it possible? IF yes then how 🙂 ?

  5. Pingback: How To: Run Tests On Different Machines In Parallel - ► Shai Raiten's Blog