10

A convenient way of running tests in parallel in nunit when in a dotnet framework project was to set this in the AssemblyInfo.cs file.

[assembly: Parallelizable(ParallelScope.Fixtures)]

however in .net core or .net standard, there is no longer an AssemblyInfo.cs file. So how can one set the scope to parallel in net core or net standard in just one place, without having to add that decorator on every single test class file?

EllaVader
  • 141
  • 1
  • 5
  • 3
    You can put an assembly attribute in any file outside the namespace. It doesn't have to be in `AssemblyInfo.cs`, you could add your own `AssemblyInfo.cs` file. That said I have no idea if NUnit will recognize it in your .Net Core project. – JSteward Nov 01 '18 at 20:02
  • 2
    @JSteward - you're right, you should post that as an answer! And NUnit supports Parallelizable in .NET Core 2.1, but not 1.1. – Chris Nov 01 '18 at 22:33
  • @JSteward thank you for your response. How exactly would you do that? If I were to just create an AssemblyInfo.cs file with the above attribute how would I tell my project to know to read it in? would you do it like outlined here? https://stackoverflow.com/questions/42138418/equivalent-to-assemblyinfo-in-dotnet-core-csproj/42183749#42183749 – EllaVader Nov 03 '18 at 02:12

1 Answers1

13

Create WhateverNameYouWant.cs file. Just put your code - NUnit will recognize it.

  using NUnit.Framework;
  [assembly: Parallelizable(ParallelScope.Fixtures)]
unickq
  • 1,497
  • 12
  • 18
  • 2
    Probably worth mentioning that this has to be outside of a namespace/class/struct/interface block, too. – Wai Ha Lee Apr 01 '19 at 12:48
  • How do you choose the number of tests you want running at the same time? [assembly:LevelOfParallelism(3)] Can i just do this anywhere ? – Shannon McRae Mar 03 '21 at 20:30