RefMa77
RefMa77

Reputation: 293

How to execute every single test in a test class in an own process

We use C# and NUnit 3.6.1 in our project and we think of parallel test execution to reduce the duration. As far as I know, it is possible to parallel the execution of TestFixture with a Parallelizable-attribute for the class in an assembly. We want to go further and parallel all tests, that are marked with Testor TestCase, inside a test class.

A typical test class looks like:

[TestFixture]
    public class MyTestClass
    {

      private MySUT _sut;
      private Mock<IDataBase> _mockedDB;

      [SetUp]
      public void SetUpSUT()
      {
        _mockedDB = new Mock<IDataBase>();
        _sut = new MySUT(_mockedDB.Object);
      }

      public void TearDownSUT()
      {
        _mockedDB = null;
        _sut = null;
      }

      [Test]
      public void MyFirstTC()
      {
        //Here do some testing stuff with _sut
      }

      [Test]
      public void MySecondTC()
      {
        //Here do some testing stuff with _sut again
      }
    }

As you can see, we have some fields, that we use in every test. To have a better separation, we think of executing every single test in an own process. I have no idea how to do that, or do we have to change something different to make parallel execution possible?

Thanks in advance!

Upvotes: 3

Views: 1509

Answers (3)

Amittai Shapira
Amittai Shapira

Reputation: 3827

Yes you can run individual tests in separate threads (not processes), starting with NUnit 3.7.
Using the ParellelScope parameter to Parallelizable attribute. From NUnit documentation:

ParallelScope Enumeration
This is a [Flags] enumeration used to specify which tests may run in parallel. It applies to the test upon which it appears and any subordinate tests. It is defined as follows:

[Flags]
public enum ParallelScope
{
    None,     // the test may not be run in parallel with other tests
    Self,     // the test itself may be run in parallel with other tests
    Children, // child tests may be run in parallel with one another
    Fixtures  // fixtures may be run in parallel with one another
}

Upvotes: 2

Charlie
Charlie

Reputation: 13736

NUnit has no builtin way to run individual tests in separate processes. It allows you to run entire assemblies in separate processes or individual tests within an assembly on separate threads, as you have discovered already.

The question has come up in the past as a possible extension to NUnit, but has never been acted on up to now because there doesn't seem to be a very wide demand for it.

Not a real positive answer, I'm afraid. :-(

Upvotes: 2

Ian Robertson
Ian Robertson

Reputation: 2812

In VSTS, you can check a box to isolate tests. You can also run in parallel or in series. In Visual Studio, I dont think its obvious/possible to do this. If its possible in VSTS, there is probably a command line you can use to pass the appropriate switches.

Upvotes: 0

Related Questions