4

I am running my unit tests ona test agent. I have changed my testsettings to use ParallelTestCount = "0" so the tests are run in parallel. I then have failing tests as the tests are using the same instance of a Mock.

Is there anyway I can run each test classes in parallel and not the individual tests?

Is there a better alternative to MSTEST command line to test my binaries?

I am running Visual Studio 2012 and TestAgent and controller 2012.

Thanks in advance

MicroMan
  • 1,988
  • 4
  • 32
  • 58
  • 1
    Is it an option to make sure that your tests don't depend on each other (by removing the shared state)? It's dangerous to create unit tests that depend on each other. – Wouter de Kort Aug 29 '13 at 11:23
  • Its not that they depend on each other but in the Test Initializer I setup Mocks that each test runs ie to reduce code... I have 200 failing tests out of 4000 and i was hoping not to refactor them... so If i could run test classes in parallel then i would not have this problem... – MicroMan Aug 29 '13 at 11:35

1 Answers1

0

There is no such option as far as I know.

These failing tests actually shows that you have a shared state between your unit tests - in this case a class field (mock).

Consider creating the shared objects in each test instead of using TestInitialize to create the mock object, if it's a completed setup then use a helper method.

I don't recommend splitting your tests between two methods and I think this minimal code duplication not only make sure that you do not have shared state but also creates more readable tests and makes sure that an accidental edit to your initialize method won't cause other tests to fail.

For more information on why I prefer not to use SetUp/TestInitialize check out James Newkirk blog, or my own thoughts on the subject.

Dror Helper
  • 30,292
  • 15
  • 80
  • 129