ParallelizableAttribute
ParallelizableAttribute is used to mark tests that may be run in parallel.
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using System;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class ParallelizableAttribute : PropertyAttribute, IApplyToContext
{
public ParallelScope Scope { get; }
public ParallelizableAttribute()
: this(ParallelScope.Self)
{
}
public ParallelizableAttribute(ParallelScope scope)
{
Scope = scope;
base.Properties.Set("ParallelScope", scope);
}
public override void ApplyToTest(Test test)
{
if (test is TestFixture && Scope.HasFlag(ParallelScope.Fixtures))
base.Properties.Set("ParallelScope", Scope | ParallelScope.Self);
base.ApplyToTest(test);
if (test.RunState != 0) {
if (Scope.HasFlag(ParallelScope.Self) && Scope.HasFlag(ParallelScope.None))
test.MakeInvalid("Test may not be both parallel and non-parallel");
if (test is TestMethod && Scope.HasFlag(ParallelScope.ContextMask))
test.MakeInvalid("ParallelScope of a test method may not specify Children or Fixtures");
}
}
public void ApplyToContext(TestExecutionContext context)
{
context.ParallelScope = (Scope & ParallelScope.ContextMask);
}
}
}