Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run NUnit tests in parallel?

Tags:

nunit

I've got a large acceptance test (~10 seconds per test) test suite written using NUnit. I would like to make use of the fact that my machines are all multiple core boxes. Ideally, I'd be able to have one test running per core, independently of other tests.

There is PNUnit, but it's designed for testing for threading synchronization issues and things like that, and I didn't see an obvious way to accomplish this.

Is there a switch/tool/option I can use to run the tests in parallel?

like image 515
Billy ONeal Avatar asked Jul 22 '10 20:07

Billy ONeal


People also ask

Can we run tests in parallel?

You can parallel test at scale by integrating test automation frameworks with a cloud-based solution, which takes care of device management. The opposite of parallel testing is sequential testing. This entails executing one test after another. This is a much more time-consuming approach to testing.

Does Visual Studio run tests in parallel?

Visual Studio 2019 runs unit tests sequentially when it is suppose to run them in parallel. Click on the Run Tests in Parallel button in Test Explorer. Make sure the icon is highlighted.

Should unit tests be run in parallel?

Running unit tests in parallel can significantly improve the speed at which they run. However, you have to make sure that one test does not affect another in any way. Else your tests are green most of the time, but sometimes one or more tests will fail. Both tests depend on IRepository .


2 Answers

If you want to run NUnit tests in parallel, there are at least 2 options:

  • NCrunch offers it out of the box (without changing anything, but is a commercial product)
  • NUnit 3 offers a Parallelizable attribute, which can be used to denote which tests can be run in parallel
like image 93
David_001 Avatar answered Sep 19 '22 12:09

David_001


NUnit version 3 will support running tests in parallel:

Adding the attribute to a class: [Parallelizable(ParallelScope.Self)] will run your tests in parallel.

• ParallelScope.None indicates that the test may not be run in parallel with other tests.

• ParallelScope.Self indicates that the test itself may be run in parallel with other tests.

• ParallelScope.Children indicates that the descendants of the test may be run in parallel with respect to one another.

• ParallelScope.Fixtures indicates that fixtures may be run in parallel with one another.

NUnit Framework-Parallel-Test-Execution

like image 30
Peter Avatar answered Sep 23 '22 12:09

Peter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!