Skip to content

Commit

Permalink
Fix ParallelizableAttribute with TestFixtureSource (#4099)
Browse files Browse the repository at this point in the history
  • Loading branch information
jairbubbles committed Apr 8, 2023
1 parent 76f7444 commit d3ed922
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Expand Up @@ -107,12 +107,14 @@ public IEnumerable<TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter)
fixtureSuite.ApplyAttributesToTest(typeInfo.Type);
var assemblyLifeCycleAttributeProvider = new AttributeProviderWrapper<FixtureLifeCycleAttribute>(typeInfo.Type.Assembly);
var typeLifeCycleAttributeProvider = new AttributeProviderWrapper<FixtureLifeCycleAttribute>(typeInfo.Type);
var parallelizableAttributeProvider = new AttributeProviderWrapper<ParallelizableAttribute>(typeInfo.Type);

foreach (ITestFixtureData parms in GetParametersFor(sourceType))
{
TestSuite fixture = _builder.BuildFrom(typeInfo, filter, parms);
fixture.ApplyAttributesToTest(assemblyLifeCycleAttributeProvider);
fixture.ApplyAttributesToTest(typeLifeCycleAttributeProvider);
fixture.ApplyAttributesToTest(parallelizableAttributeProvider);
fixtureSuite.Add(fixture);
}

Expand Down
21 changes: 21 additions & 0 deletions src/NUnitFramework/testdata/TestFixtureSourceData.cs
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace NUnit.TestData.TestFixtureSourceData
{
Expand Down Expand Up @@ -509,3 +510,23 @@ public void Test()
static object[] MyData = { 1 };
#pragma warning restore 414
}

[TestFixtureSource("Data")]
[Parallelizable(ParallelScope.All)]
public class TextFixtureSourceWithParallelizableAttribute
{
public TextFixtureSourceWithParallelizableAttribute(string arg) { }

static IEnumerable Data()
{
yield return new TestFixtureData("a");
yield return new TestFixtureData("b");
yield return new TestFixtureData("c");
}

[Test]
public void Test()
{
Thread.Sleep(1000);
}
}
14 changes: 14 additions & 0 deletions src/NUnitFramework/tests/Attributes/TestFixtureSourceTests.cs
Expand Up @@ -164,5 +164,19 @@ public void CanRunGenericFixtureSourceWithConstructorArgsProvidedAndTypeArgsDedu
Assert.That(suite.Tests[0] is ParameterizedFixtureSuite);
Assert.That(suite.Tests[0].Tests.Count, Is.EqualTo(GenericFixtureWithConstructorArgsSource.Source.Length));
}

[Test]
public void ParallelizableAttributeOnFixtureSourceIsAppliedToTests()
{
TestSuite suite = TestBuilder.MakeFixture(typeof(TextFixtureSourceWithParallelizableAttribute));
Assert.That(suite.RunState, Is.EqualTo(RunState.Runnable));
Assert.That(suite, Is.TypeOf<ParameterizedFixtureSuite>());
Assert.That(suite.TestCaseCount, Is.EqualTo(3));
Assert.That(suite.Tests.Count, Is.EqualTo(3));

Assert.That(suite.Tests[0].Properties.Get(PropertyNames.ParallelScope), Is.EqualTo(ParallelScope.All));
Assert.That(suite.Tests[1].Properties.Get(PropertyNames.ParallelScope), Is.EqualTo(ParallelScope.All));
Assert.That(suite.Tests[2].Properties.Get(PropertyNames.ParallelScope), Is.EqualTo(ParallelScope.All));
}
}
}

0 comments on commit d3ed922

Please sign in to comment.