public void CollectsTestCases() { var visitor = new TestDiscoverySink(); var testCase1 = Substitute.For<ITestCase>(); var testCase2 = Substitute.For<ITestCase>(); var testCase3 = Substitute.For<ITestCase>(); visitor.OnMessageWithTypes(new DiscoveryMessage(testCase1),null); visitor.OnMessageWithTypes(new DiscoveryMessage(testCase2),null); visitor.OnMessageWithTypes(new DiscoveryMessage(testCase3), null); visitor.OnMessageWithTypes(Substitute.For<IMessageSinkMessage>(), null); // Ignored Assert.Collection(visitor.TestCases, msg => Assert.Same(testCase1, msg), msg => Assert.Same(testCase2, msg), msg => Assert.Same(testCase3, msg) ); }
public static void TheoriesWithSerializableData_ReturnAsIndividualTestCases() { var sourceProvider = new NullSourceInformationProvider(); var assemblyInfo = Reflector.Wrap(Assembly.GetExecutingAssembly()); var discoverer = new XunitTestFrameworkDiscoverer(assemblyInfo, sourceProvider, SpyMessageSink.Create()); var sink = new TestDiscoverySink(); discoverer.Find(typeof(ClassWithTheory).FullName, false, sink, TestFrameworkOptions.ForDiscovery()); sink.Finished.WaitOne(); var first = sink.TestCases[0]; var second = sink.TestCases[1]; Assert.NotEqual(first.UniqueID, second.UniqueID); Assert.True(TestCollectionComparer.Instance.Equals(first.TestMethod.TestClass.TestCollection, second.TestMethod.TestClass.TestCollection)); var serializedFirst = SerializationHelper.Deserialize<ITestCase>(SerializationHelper.Serialize(first)); var serializedSecond = SerializationHelper.Deserialize<ITestCase>(SerializationHelper.Serialize(second)); Assert.NotSame(serializedFirst.TestMethod.TestClass.TestCollection, serializedSecond.TestMethod.TestClass.TestCollection); Assert.True(TestCollectionComparer.Instance.Equals(serializedFirst.TestMethod.TestClass.TestCollection, serializedSecond.TestMethod.TestClass.TestCollection)); }
protected TestableXunitTestFrameworkDiscoverer(IAssemblyInfo assembly, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory) : base(assembly, sourceProvider ?? Substitute.For<ISourceInformationProvider>(), diagnosticMessageSink ?? new Xunit.NullMessageSink(), collectionFactory) { Assembly = assembly; Sink = new TestDiscoverySink(); }
public static void TheoryWithNonSerializableData_ReturnsAsASingleTestCase() { var sourceProvider = new NullSourceInformationProvider(); var assemblyInfo = Reflector.Wrap(Assembly.GetExecutingAssembly()); var discoverer = new XunitTestFrameworkDiscoverer(assemblyInfo, sourceProvider, SpyMessageSink.Create()); var sink = new TestDiscoverySink(); discoverer.Find(typeof(ClassWithNonSerializableTheoryData).FullName, false, sink, TestFrameworkOptions.ForDiscovery()); sink.Finished.WaitOne(); var testCase = Assert.Single(sink.TestCases); Assert.IsType<XunitTheoryTestCase>(testCase); var deserialized = SerializationHelper.Deserialize<ITestCase>(SerializationHelper.Serialize(testCase)); Assert.IsType<XunitTheoryTestCase>(deserialized); }
public void TheoryWithInlineData() { string code = @" module FSharpTests open Xunit [<Theory>] [<InlineData>] [<InlineData(42)>] [<InlineData(42, 21.12)>] let TestMethod (x:int) = Assert.True(true) "; using (var assembly = FSharpAcceptanceTestV2Assembly.Create(code)) using (var controller = new TestableXunit2(assembly.FileName, null, true)) { var sink = new TestDiscoverySink(); controller.Find(includeSourceInformation: false, messageSink: sink, discoveryOptions: TestFrameworkOptions.ForDiscovery()); sink.Finished.WaitOne(); Assert.Collection(sink.TestCases.OrderBy(tc => tc.DisplayName), testCase => Assert.Equal("FSharpTests.TestMethod(x: ???)", testCase.DisplayName), testCase => Assert.Equal("FSharpTests.TestMethod(x: 42)", testCase.DisplayName), testCase => Assert.Equal("FSharpTests.TestMethod(x: 42, ???: 21.12)", testCase.DisplayName) ); } }
public void FactAcceptanceTest() { string code = @" module FSharpTests open Xunit [<Fact>] [<Trait(""Name!"", ""Value!"")>] let Trait() = Assert.True(true) [<Fact(Skip = ""Skipping"")>] let Skipped() = Assert.True(false) [<Fact(DisplayName=""Custom Test Name"")>] let CustomName() = Assert.True(true) "; using (var assembly = FSharpAcceptanceTestV2Assembly.Create(code)) using (var controller = new TestableXunit2(assembly.FileName, null, true)) { var sink = new TestDiscoverySink(); controller.Find(includeSourceInformation: false, messageSink: sink, discoveryOptions: TestFrameworkOptions.ForDiscovery()); sink.Finished.WaitOne(); Assert.Collection(sink.TestCases.OrderBy(tc => tc.DisplayName), testCase => Assert.Equal("Custom Test Name", testCase.DisplayName), testCase => { Assert.Equal("FSharpTests.Skipped", testCase.DisplayName); Assert.Equal("Skipping", testCase.SkipReason); }, testCase => { Assert.Equal("FSharpTests.Trait", testCase.DisplayName); Assert.Collection(testCase.Traits, kvp => { Assert.Equal("Name!", kvp.Key); Assert.Equal("Value!", kvp.Value.Single()); } ); } ); } }
public void FindByAssemblyReturnsAllTestMethodsFromExecutorXml() { var xml = @" <assembly> <class name='Type1'> <method name='Method1 Display Name' type='Type1' method='Method1'/> </class> <class name='SpecialType'> <method name='SpecialType.SkippedMethod' type='SpecialType' method='SkippedMethod' skip='I am not run'/> <method name='SpecialType.MethodWithTraits' type='SpecialType' method='MethodWithTraits'> <traits> <trait name='Trait1' value='Value1'/> <trait name='Trait2' value='Value2'/> </traits> </method> </class> </assembly>"; using (var xunit1 = new TestableXunit1()) { xunit1.Executor .WhenForAnyArgs(x => x.EnumerateTests(null)) .Do(callInfo => callInfo.Arg<ICallbackEventHandler>().RaiseCallbackEvent(xml)); var sink = new TestDiscoverySink(); xunit1.Find(false, sink); sink.Finished.WaitOne(); Assert.Collection(sink.TestCases, testCase => { Assert.Equal("Type1", testCase.TestMethod.TestClass.Class.Name); Assert.Equal("Method1", testCase.TestMethod.Method.Name); Assert.Equal("Method1 Display Name", testCase.DisplayName); Assert.Null(testCase.SkipReason); Assert.Empty(testCase.Traits); }, testCase => { Assert.Equal("SpecialType", testCase.TestMethod.TestClass.Class.Name); Assert.Equal("SkippedMethod", testCase.TestMethod.Method.Name); Assert.Equal("SpecialType.SkippedMethod", testCase.DisplayName); Assert.Equal("I am not run", testCase.SkipReason); }, testCase => { Assert.Equal("SpecialType", testCase.TestMethod.TestClass.Class.Name); Assert.Equal("MethodWithTraits", testCase.TestMethod.Method.Name); Assert.Equal("SpecialType.MethodWithTraits", testCase.DisplayName); Assert.Collection(testCase.Traits.Keys, key => { Assert.Equal("Trait1", key); Assert.Collection(testCase.Traits[key], value => Assert.Equal("Value1", value) ); }, key => { Assert.Equal("Trait2", key); Assert.Collection(testCase.Traits[key], value => Assert.Equal("Value2", value) ); } ); } ); } }
public void TestCasesUseInformationFromSourceInformationProvider() { var xml = @" <assembly> <class name='Type2'> <method name='Type2.Method1' type='Type2' method='Method1'/> <method name='Type2.Method2' type='Type2' method='Method2'/> </class> </assembly>"; using (var xunit1 = new TestableXunit1()) { xunit1.Executor .WhenForAnyArgs(x => x.EnumerateTests(null)) .Do(callInfo => callInfo.Arg<ICallbackEventHandler>().RaiseCallbackEvent(xml)); xunit1.SourceInformationProvider .GetSourceInformation(null) .ReturnsForAnyArgs(callInfo => new SourceInformation { FileName = "File for " + callInfo.Arg<ITestCase>().DisplayName }); var sink = new TestDiscoverySink(); xunit1.Find(true, sink); sink.Finished.WaitOne(); Assert.Collection(sink.TestCases, testCase => Assert.Equal("File for Type2.Method1", testCase.SourceInformation.FileName), testCase => Assert.Equal("File for Type2.Method2", testCase.SourceInformation.FileName) ); } }
public void FindByTypesReturnsOnlyMethodsInTheGivenType() { var xml = @" <assembly> <class name='Type1'> <method name='Method1 Display Name' type='Type1' method='Method1'/> </class> <class name='Type2'> <method name='Type2.Method1' type='Type2' method='Method1'/> <method name='Type2.Method2' type='Type2' method='Method2'/> </class> </assembly>"; using (var xunit1 = new TestableXunit1()) { xunit1.Executor .WhenForAnyArgs(x => x.EnumerateTests(null)) .Do(callInfo => callInfo.Arg<ICallbackEventHandler>().RaiseCallbackEvent(xml)); var sink = new TestDiscoverySink(); xunit1.Find("Type2", false, sink); sink.Finished.WaitOne(); Assert.Collection(sink.TestCases, testCase => Assert.Equal("Type2.Method1", testCase.DisplayName), testCase => Assert.Equal("Type2.Method2", testCase.DisplayName) ); } }