Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does NUnit (and MSTest) handle tests that change static/shared variables?

I have some code that uses the shared gateway pattern to implement an inversion of control container. I have several hundred NUnit unit tests that exercises the code that uses this IOC. They all work (on my machine!) but I am concerned that these tests might fail under load. I seem to remember that NUnit (and MSTest) attempts to run tests in parallel on multiple threads (which would definitely trigger race conditions on the static/shared gateway) but I cannot find any documentation that says what actually happens. My experience is that NUnit seems to be running the tests sequencially. My question is, does NUnit (or MSTest) ever run unit tests in parallel? If so, under what conditions? And, can I turn this off via some sort of configuration option?

like image 800
JonStonecash Avatar asked Sep 30 '08 17:09

JonStonecash


People also ask

What is the difference between MSTest and NUnit test?

MsTest is a native unit testing library that comes with Visual Studio from Microsoft. NUnit is an extra Nuget package that needs to be installed on top and interact with the APIs of Visual Studio. Nunit likely doesn't have direct integration into the native APIs like MsTest does.

What is the difference between xUnit and NUnit and MSTest?

As far as NUnit vs. XUnit vs. MSTest is concerned, the biggest difference between xUnit and the other two test frameworks (NUnit and MSTest) is that xUnit is much more extensible when compared to NUnit and MSTest. The [Fact] attribute is used instead of the [Test] attribute.

What is MSTest used for?

MSTest is one type of framework that provides the facility to test the code without using any third-party tool. It helps in writing effective unit tests using MSTest framework to test software applications. MSTest is a number-one open-source test framework that is shipped along with the Visual Studio IDE.

How can you make a NUnit TestCase Datadriven?

The first way to create data driven tests is by using the [TestCase] attribute that NUnit provides. You can add multiple [TestCase] attributes for a single test method, and specify the combinations of input and expected output parameters that the test method should take.


1 Answers

Update:

Visual Studio 2010 introduced the ability to run tests in parallel.

Here is a step by step article about how to enable this.

MsTest:
So according to David Williamson, from Microsoft Visual Studio Team System, on this post in the MSDN forums:

Tests absolutely do NOT run in parallel when run in VS or via mstest.exe. If they are run in a Load Test through VS then that is a different story. Basic execution, however, is always serial.

Also, tests run using MsTest are each run using a different thread in order to ensure that you have a clean slate for each test. There is no way to disable this behavior.

NUnit:
NUnit runs all tests on the same thread.

like image 63
Josh Avatar answered Oct 28 '22 08:10

Josh