public static void IncompatibleOrInvalidTypesGetDefaultBehavior(string factoryTypeName) { var attr = Mocks.CollectionBehaviorAttribute(factoryTypeName, "test.xunit.execution"); var assembly = Mocks.TestAssembly(); var result = ExtensibilityPointFactory.GetXunitTestCollectionFactory(attr, assembly); Assert.IsType <CollectionPerClassTestCollectionFactory>(result); }
public void UserCanChooseFromBuiltInCollectionFactories_NonParallel(CollectionBehavior behavior, Type expectedType) { var attr = Mocks.CollectionBehaviorAttribute(behavior); var assembly = Mocks.TestAssembly(); var result = ExtensibilityPointFactory.GetXunitTestCollectionFactory(spy, attr, assembly); Assert.IsType(expectedType, result); }
public static void CustomCollectionFactory() { var behaviorAttribute = Mocks.CollectionBehaviorAttribute <CustomTestCollectionFactory>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[my-custom-test-collection-factory, parallel\]", discoverer.TestFrameworkDisplayName); }
public static void NonParallel() { var behaviorAttribute = Mocks.CollectionBehaviorAttribute(disableTestParallelization: true); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[collection-per-class, non-parallel\]", discoverer.TestFrameworkDisplayName); }
public static void ValidCustomFactory() { var behaviorAttribute = Mocks.CollectionBehaviorAttribute <CustomTestCollectionFactory>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.IsType <CustomTestCollectionFactory>(discoverer.TestCollectionFactory); }
public static void Attribute_NonParallel() { var attribute = Mocks.CollectionBehaviorAttribute(disableTestParallelization: true); var assembly = Mocks.TestAssembly(new[] { attribute }); var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly); var result = runner.GetTestFrameworkEnvironment(); Assert.EndsWith("[collection-per-class, non-parallel]", result); }
public static void Attribute_MaxThreads() { var attribute = Mocks.CollectionBehaviorAttribute(maxParallelThreads: 3); var assembly = Mocks.TestAssembly(new[] { attribute }); var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly); var result = runner.GetTestFrameworkEnvironment(); Assert.EndsWith("[collection-per-class, parallel (3 threads)]", result); }
public static void Attribute_CollectionBehavior(CollectionBehavior behavior, string expectedDisplayText) { var attribute = Mocks.CollectionBehaviorAttribute(behavior, disableTestParallelization: true); var assembly = Mocks.TestAssembly(new[] { attribute }); var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly); var result = runner.GetTestFrameworkEnvironment(); Assert.EndsWith(string.Format("[{0}, non-parallel]", expectedDisplayText), result); }
public static async ValueTask Attribute_Unlimited() { var attribute = Mocks.CollectionBehaviorAttribute(maxParallelThreads: -1); var assembly = Mocks.TestAssembly("assembly.dll", assemblyAttributes: new[] { attribute }); await using var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly); var result = runner.GetTestFrameworkEnvironment(); Assert.EndsWith("[collection-per-class, parallel (unlimited threads)]", result); }
public static void UserCanChooseFromBuiltInCollectionFactories_NonParallel(CollectionBehavior behavior, Type expectedType, string expectedDisplayText) { var attr = Mocks.CollectionBehaviorAttribute(behavior, disableTestParallelization: true); var assembly = Mocks.AssemblyInfo(attributes: new[] { attr }); var sourceInfoProvider = Substitute.For <ISourceInformationProvider>(); var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider); Assert.IsType(expectedType, discoverer.TestCollectionFactory); Assert.Equal(String.Format("{0} [{1}, non-parallel]", XunitTestFrameworkDiscoverer.DisplayName, expectedDisplayText), discoverer.TestFrameworkDisplayName); }
public void IncompatibleOrInvalidTypesGetDefaultBehavior(string factoryTypeName) { var attr = Mocks.CollectionBehaviorAttribute(factoryTypeName, "test.xunit2"); var assembly = Mocks.AssemblyInfo(attributes: new[] { attr }); var sourceInfoProvider = Substitute.For <ISourceInformationProvider>(); var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider); Assert.IsType <CollectionPerClassTestCollectionFactory>(discoverer.TestCollectionFactory); Assert.Equal(XunitTestFrameworkDiscoverer.DisplayName + " [collection-per-class, parallel]", discoverer.TestFrameworkDisplayName); }
public void UserCanChooseFromBuiltInCollectionFactories_NonParallel() { var attr = Mocks.CollectionBehaviorAttribute(CollectionBehavior.CollectionPerAssembly, disableTestParallelization: true); var assembly = Mocks.AssemblyInfo(attributes: new[] { attr }); var sourceInfoProvider = Substitute.For <ISourceInformationProvider>(); var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider); Assert.IsType <CollectionPerAssemblyTestCollectionFactory>(discoverer.TestCollectionFactory); Assert.Equal(XunitTestFrameworkDiscoverer.DisplayName + " [collection-per-assembly, non-parallel]", discoverer.TestFrameworkDisplayName); }
public static void AssemblyAttributeOverride( CollectionBehavior behavior, Type expectedFactoryType) { var behaviorAttribute = Mocks.CollectionBehaviorAttribute(behavior); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.IsType(expectedFactoryType, discoverer.TestCollectionFactory); }
public static async ValueTask Attribute_CollectionBehavior(CollectionBehavior behavior, string expectedDisplayText) { var attribute = Mocks.CollectionBehaviorAttribute(behavior, disableTestParallelization: true); var assembly = Mocks.TestAssembly("assembly.dll", assemblyAttributes: new[] { attribute }); await using var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly); var result = runner.GetTestFrameworkEnvironment(); Assert.EndsWith($"[{expectedDisplayText}, non-parallel]", result); }
public void UserCanChooseCustomCollectionFactoryWithType() { var attr = Mocks.CollectionBehaviorAttribute <MyTestCollectionFactory>(); var assembly = Mocks.TestAssembly(); var result = ExtensibilityPointFactory.GetXunitTestCollectionFactory(spy, attr, assembly); var myFactory = Assert.IsType <MyTestCollectionFactory>(result); Assert.Same(assembly, myFactory.Assembly); }
public static void Attribute_CustomCollectionFactory() { var factoryType = typeof(MyTestCollectionFactory); var attr = Mocks.CollectionBehaviorAttribute(factoryType.FullName, factoryType.Assembly.FullName, disableTestParallelization: true); var assembly = Mocks.TestAssembly(new[] { attr }); var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly); var result = runner.GetTestFrameworkEnvironment(); Assert.EndsWith("[My Factory, non-parallel]", result); }
public static async ValueTask Attribute_MaxThreads() { var attribute = Mocks.CollectionBehaviorAttribute(maxParallelThreads: 3); var assembly = Mocks.TestAssembly("assembly.dll", assemblyAttributes: new[] { attribute }); await using var context = TestableXunitTestAssemblyRunnerContext.Create(assembly: assembly); await context.InitializeAsync(); var result = context.TestFrameworkEnvironment; Assert.EndsWith("[collection-per-class, parallel (3 threads)]", result); }
public void UserCanChooseCustomCollectionFactory() { var factoryType = typeof(MyTestCollectionFactory); var attr = Mocks.CollectionBehaviorAttribute(factoryType.FullName, factoryType.Assembly.FullName); var assembly = Mocks.AssemblyInfo(attributes: new[] { attr }); var sourceInfoProvider = Substitute.For <ISourceInformationProvider>(); var discoverer = new XunitTestFrameworkDiscoverer(assembly, sourceInfoProvider); Assert.IsType <MyTestCollectionFactory>(discoverer.TestCollectionFactory); Assert.Equal(XunitTestFrameworkDiscoverer.DisplayName + " [My Factory, parallel]", discoverer.TestFrameworkDisplayName); }
public void IncompatibleOrInvalidTypesGetDefaultBehavior(string factoryTypeName, string expectedMessage) { var attr = Mocks.CollectionBehaviorAttribute(factoryTypeName, "xunit.v2.tests"); var assembly = Mocks.TestAssembly(); var result = ExtensibilityPointFactory.GetXunitTestCollectionFactory(spy, attr, assembly); Assert.IsType <CollectionPerClassTestCollectionFactory>(result); Assert.Collection(DiagnosticMessages, msg => Assert.Equal(expectedMessage, msg) ); }
public static void UserCanChooseCustomCollectionFactory() { var factoryType = typeof(MyTestCollectionFactory); var attr = Mocks.CollectionBehaviorAttribute(factoryType.FullName, factoryType.Assembly.FullName); var assembly = Mocks.TestAssembly(); var result = ExtensibilityPointFactory.GetXunitTestCollectionFactory(attr, assembly); var myFactory = Assert.IsType <MyTestCollectionFactory>(result); Assert.Same(assembly, myFactory.Assembly); }
public static void TestOptionsOverrideAttribute() { var attribute = Mocks.CollectionBehaviorAttribute(disableTestParallelization: true, maxParallelThreads: 127); var options = new XunitExecutionOptions { DisableParallelization = false, MaxParallelThreads = 3 }; var assembly = Mocks.TestAssembly(new[] { attribute }); var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly, options: options); var result = runner.GetTestFrameworkEnvironment(); Assert.EndsWith("[collection-per-class, parallel (3 threads)]", result); }
public static async ValueTask TestOptionsOverrideAttribute() { var attribute = Mocks.CollectionBehaviorAttribute(disableTestParallelization: true, maxParallelThreads: 127); var options = _TestFrameworkOptions.ForExecution(); options.SetDisableParallelization(false); options.SetMaxParallelThreads(3); var assembly = Mocks.TestAssembly("assembly.dll", assemblyAttributes: new[] { attribute }); await using var runner = TestableXunitTestAssemblyRunner.Create(assembly: assembly, executionOptions: options); var result = runner.GetTestFrameworkEnvironment(); Assert.EndsWith("[collection-per-class, parallel (3 threads)]", result); }
public static void InvalidCustomFactoryFallsBackToDefault() { var spyMessageSink = SpyMessageSink.Capture(); TestContext.Current !.DiagnosticMessageSink = spyMessageSink; var behaviorAttribute = Mocks.CollectionBehaviorAttribute <object>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.IsType <CollectionPerClassTestCollectionFactory>(discoverer.TestCollectionFactory); var message = Assert.Single(spyMessageSink.Messages); var diagMessage = Assert.IsType <_DiagnosticMessage>(message); Assert.Equal("Test collection factory type 'System.Object' does not implement IXunitTestCollectionFactory", diagMessage.Message); }
public void IncompatibleOrInvalidTypesGetDefaultBehavior(string factoryTypeName, string expectedMessage) { var spy = SpyMessageSink.Capture(); TestContext.Current !.DiagnosticMessageSink = spy; #if BUILD_X86 expectedMessage = expectedMessage.Replace("xunit.v3.core.tests", "xunit.v3.core.tests.x86"); var attr = Mocks.CollectionBehaviorAttribute(factoryTypeName, "xunit.v3.core.tests.x86"); #else var attr = Mocks.CollectionBehaviorAttribute(factoryTypeName, "xunit.v3.core.tests"); #endif var assembly = Mocks.TestAssembly(); var result = ExtensibilityPointFactory.GetXunitTestCollectionFactory(attr, assembly); AssertSingleDiagnosticMessage(spy, expectedMessage); }