The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Run your unit tests in parallel with NUnit

Posted by jpluimers on 2021/01/26

TL;DR

The examples in this post are specific for NUnit but, you can apply this pattern for safely running unit tests in parallel to any unit test framework that supports parallel execution.

To safely run tests in parallel, do the following:

  1. Mark your test fixtures with the Parallelizable attribute and set the parallel scope to ParallelScope.All.
  2. Create a private class called TestScope and implement IDisposable.
  3. Put all startup and clean-up logic inside the TestScope constructor and .Dispose() method respectively.
  4. Wrap your test code in a using (var scope = new TestScope) { ... } block

From [WayBack] Run your unit tests in parallel with NUnit, which also covers:

  • Background (on why you might want this)
  • How to safely run tests in parallel
  • Maximizing parallel execution with Visual Studio
  • Maximizing parallel execution with Azure DevOps

Via: [WayBack] Sander Aernouts on Twitter: “Run unit tests in parallel with NUnit without having one test interfere with another test. https://t.co/FC0fNocGov”

–jeroen

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.