Issue in excluding nunit test fixtures from parallel execution

68 views Asked by At

AssemblyInfo.cs

using NUnit.Framework;
[assembly: Parallelizable(ParallelScope.Fixtures)]
[assembly: LevelOfParallelism(3)]

Now I have 55 test classes in my suite, and I have marked only 5 test class as [Parallelizable(ParallelScope.Fixtures)]. When I try to execute the tests from any test class its running parallelly. I need only the 5 test class to run in parallel and other 50 test class should run sequentially.

I tried adding [NonParallelizable] in remaining test class but it didn't help. Any solution or suggestion is welcome..

Nunit version is 3.13.3

2

There are 2 answers

2
Shatas On

Try this:

using NUnit.Framework;

[assembly: LevelOfParallelism(3)]
namespace YourProject.YourFolder
{
    [Parallelizable(ParallelScope.Fixtures)]
    public class YourClass
    {

    }
}

Change the scope as needed according to your specific solution. I would suggest using ParallelScope.Children if you have all the test that you want to run in parallel in the same class.

4
Michał Cichoń On

I think you set [assembly: Parallelizable(ParallelScope.Fixtures)] globally for your assembly, so all tests will be executed in parallel in your assembly.

Easiest way for "turning on" parallel execution is creating .runsettings file with "nunit config" and using Parallelizable attribute with specific ParallelScope for your test method or class in code for example [Parallelizable(ParallelScope.Fixtures)].

<RunSettings>
   <NUnit>
       <NumberOfTestWorkers>2</NumberOfTestWorkers>
   </NUnit>
</RunSettings>

In your case you should add [Parallelizable(ParallelScope.Fixtures)] attribute for class which requires parallel fixtures execution, other classes without this attribute will not run in parallel.