public static void WritesXmlV1ToDisk() { var tempFile = Path.GetTempFileName(); try { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For <ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xmlTaskItem = Substitute.For <ITaskItem>(); xmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, XmlV1 = xmlTaskItem }; xunit.Execute(); new XmlDocument().Load(tempFile); // File should exist as legal XML } finally { File.Delete(tempFile); } }
public static void WritesHtmlToDisk() { var tempFile = Path.GetTempFileName(); File.Delete(tempFile); try { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For <ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var htmlTaskItem = Substitute.For <ITaskItem>(); htmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, Html = htmlTaskItem }; xunit.Execute(); Assert.True(File.Exists(tempFile)); } finally { File.Delete(tempFile); } }
public static void ChangesCurrentDirectoryWhenWorkingFolderIsNotNull() { var tempFolder = Environment.GetEnvironmentVariable("TEMP"); tempFolder = Path.GetFullPath(tempFolder); // Ensure that the 8.3 path is not used var xunit = new Testable_xunit { WorkingFolder = tempFolder }; xunit.Execute(); string actual = Directory.GetCurrentDirectory(); string expected = tempFolder; if (actual[actual.Length - 1] != Path.DirectorySeparatorChar) { actual += Path.DirectorySeparatorChar; } if (expected[expected.Length - 1] != Path.DirectorySeparatorChar) { expected += Path.DirectorySeparatorChar; } Assert.Equal(expected, actual); }
public static void DoesNotRunFilteredTests() { var xunit = new Testable_xunit { ExcludeTraits = "One=1" }; var testCase1 = Substitute.For <ITestCase>(); testCase1.Traits.Returns(new Dictionary <string, List <string> >()); xunit.DiscoveryTestCases.Add(testCase1); var testCase2 = Substitute.For <ITestCase>(); testCase2.Traits.Returns(new Dictionary <string, List <string> > { { "One", new List <string> { "1" } } }); xunit.DiscoveryTestCases.Add(testCase2); var runTestCases = new List <ITestCase>(); xunit.FrontController.WhenAny(fc => fc.RunTests((IEnumerable <ITestCase>)null, null, null)) .Do(callInfo => { runTestCases.AddRange((IEnumerable <ITestCase>)callInfo[0]); }); xunit._ExecuteAssembly("assembyFileName", "configFilename"); Assert.Equal(1, runTestCases.Count); Assert.Contains(testCase1, runTestCases); Assert.DoesNotContain(testCase2, runTestCases); }
public static void VisitorIsTeamCityVisitorWhenTeamCityIsTrue() { var xunit = new Testable_xunit { TeamCity = true }; var visitor = xunit._CreateVisitor("filename"); Assert.IsType<TeamCityVisitor>(visitor); }
public void NoReporters_UsesDefaultReporter() { var xunit = new Testable_xunit(); var reporter = xunit.GetReporter(); Assert.IsType <DefaultRunnerReporter>(reporter); }
public static void ReturnsTrueWhenExitCodeIsZeroAndFailCountIsZero() { var xunit = new Testable_xunit(exitCode: 0); var result = xunit.Execute(); Assert.True(result); }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); xunit.BuildEngine.Received().LogMessageEvent(Arg.Is<BuildMessageEventArgs>(bmea => ValidateWelcomeBanner(bmea))); }
public static void ReturnsFalseWhenExitCodeIsNonZero() { var xunit = new Testable_xunit(exitCode: 1); var result = xunit.Execute(); Assert.False(result); }
public static void DefaultVisitorIsStandardOutputVisitor() { var xunit = new Testable_xunit { TeamCity = false }; var visitor = xunit._CreateVisitor("filename"); Assert.IsType<StandardOutputVisitor>(visitor); }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); xunit.BuildEngine.Received().LogMessageEvent(Arg.Is <BuildMessageEventArgs>(bmea => ValidateWelcomeBanner(bmea))); }
public static void DisposesOfFrontController() { var xunit = new Testable_xunit(); xunit._ExecuteAssembly("assemblyFilename", "configFilename"); xunit.FrontController.Received().Dispose(); }
public static void DiscoversAllTestsInAssembly() { var xunit = new Testable_xunit(); xunit._ExecuteAssembly("assemblyFilename", "configFilename"); xunit.FrontController.Received().Find(false, Arg.Any <IMessageSink>(), Arg.Any <TestFrameworkOptions>()); }
public static void DoesNotChangeCurrentDirectoryWhenWorkingFolderIsNull() { var currentFolder = Directory.GetCurrentDirectory(); var xunit = new Testable_xunit(); xunit.Execute(); Assert.Equal(currentFolder, Directory.GetCurrentDirectory()); }
public void ChangesCurrentDirectoryWhenWorkingFolderIsNotNull() { var tempFolder = Environment.GetEnvironmentVariable("TEMP"); var xunit = new Testable_xunit { WorkingFolder = tempFolder }; xunit.Execute(); Assert.Equal(tempFolder, Directory.GetCurrentDirectory()); }
public static void ChangesCurrentDirectoryWhenWorkingFolderIsNotNull() { var tempFolder = Environment.GetEnvironmentVariable("TEMP"); tempFolder = Path.GetFullPath(tempFolder); // Ensure that the 8.3 path is not used var xunit = new Testable_xunit { WorkingFolder = tempFolder }; xunit.Execute(); Assert.Equal(tempFolder, Directory.GetCurrentDirectory()); }
public static void VisitorIsTeamCityVisitorWhenTeamCityIsTrue() { var xunit = new Testable_xunit { TeamCity = true }; var visitor = xunit._CreateVisitor("filename"); Assert.IsType <TeamCityVisitor>(visitor); }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); var eventArgs = Assert.IsType<BuildMessageEventArgs>(xunit.BuildEngine.Captured(x => x.LogMessageEvent(null)).Args().Single()); Assert.Equal(string.Format("xUnit.net MSBuild Runner ({0}-bit .NET {1})", IntPtr.Size * 8, Environment.Version), eventArgs.Message); Assert.Equal(MessageImportance.High, eventArgs.Importance); }
public static void DefaultVisitorIsStandardOutputVisitor() { var xunit = new Testable_xunit { TeamCity = false }; var visitor = xunit._CreateVisitor("filename"); Assert.IsType <StandardOutputVisitor>(visitor); }
public void NoExplicitReporter_NoEnvironmentallyEnabledReporters_UsesDefaultReporter() { var implicitReporter = Mocks.RunnerReporter(isEnvironmentallyEnabled: false); var xunit = new Testable_xunit(); xunit.AvailableReporters.Add(implicitReporter); var reporter = xunit.GetReporter(); Assert.IsType <DefaultRunnerReporter>(reporter); }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); var eventArgs = Assert.IsType <BuildMessageEventArgs>(xunit.BuildEngine.Captured(x => x.LogMessageEvent(null)).Args().Single()); Assert.Equal(string.Format("xUnit.net MSBuild Runner ({0}-bit .NET {1})", IntPtr.Size * 8, Environment.Version), eventArgs.Message); Assert.Equal(MessageImportance.High, eventArgs.Importance); }
public static void LogsWelcomeBanner() { var xunit = new Testable_xunit(); xunit.Execute(); var versionAttribute = typeof(xunit).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>(); var eventArgs = Assert.IsType <BuildMessageEventArgs>(xunit.BuildEngine.Captured(x => x.LogMessageEvent(null)).Args().Single()); Assert.Equal($"xUnit.net v3 MSBuild Runner v{versionAttribute!.InformationalVersion} ({IntPtr.Size * 8}-bit {RuntimeInformation.FrameworkDescription})", eventArgs.Message); Assert.Equal(MessageImportance.High, eventArgs.Importance); }
public void NoExplicitReporter_SelectsFirstEnvironmentallyEnabledReporter() { var explicitReporter = Mocks.RunnerReporter("switch"); var implicitReporter1 = Mocks.RunnerReporter(isEnvironmentallyEnabled: true); var implicitReporter2 = Mocks.RunnerReporter(isEnvironmentallyEnabled: true); var xunit = new Testable_xunit(); xunit.AvailableReporters.AddRange(new[] { explicitReporter, implicitReporter1, implicitReporter2 }); var reporter = xunit.GetReporter(); Assert.Same(implicitReporter1, reporter); }
public void ExplicitReporter_NoEnvironmentalOverride_UsesExplicitReporter() { var explicitReporter = Mocks.RunnerReporter("switch"); var xunit = new Testable_xunit { Reporter = "switch" }; xunit.AvailableReporters.Add(explicitReporter); var reporter = xunit.GetReporter(); Assert.Same(explicitReporter, reporter); }
public void WithEnvironmentalOverride_WithEnvironmentalOverridesDisabled_UsesDefaultReporter() { var implicitReporter = Mocks.RunnerReporter(isEnvironmentallyEnabled: true); var xunit = new Testable_xunit { NoAutoReporters = true }; xunit.AvailableReporters.Add(implicitReporter); var reporter = xunit.GetReporter(); Assert.IsType <DefaultRunnerReporter>(reporter); }
public void BadChosenReporter_NoAvailableReporters() { var xunit = new Testable_xunit { Reporter = "foo" }; var reporter = xunit.GetReporter(); Assert.Null(reporter); var eventArgs = Assert.IsType <BuildErrorEventArgs>(xunit.BuildEngine.Captured(x => x.LogErrorEvent(null)).Args().Single()); Assert.Equal("Reporter value 'foo' is invalid. There are no available reporters.", eventArgs.Message); }
public void ExplicitReporter_WithEnvironmentalOverride_UsesEnvironmentalOverride() { var explicitReporter = Mocks.RunnerReporter("switch"); var implicitReporter = Mocks.RunnerReporter(isEnvironmentallyEnabled: true); var xunit = new Testable_xunit { Reporter = "switch" }; xunit.AvailableReporters.AddRange(new[] { explicitReporter, implicitReporter }); var reporter = xunit.GetReporter(); Assert.Same(implicitReporter, reporter); }
public void BadChosenReporter_WithAvailableReporters() { var xunit = new Testable_xunit { Reporter = "foo" }; xunit.AvailableReporters.AddRange(new[] { Mocks.RunnerReporter("switch1"), Mocks.RunnerReporter("switch2") }); var reporter = xunit.GetReporter(); Assert.Null(reporter); var eventArgs = Assert.IsType <BuildErrorEventArgs>(xunit.BuildEngine.Captured(x => x.LogErrorEvent(null)).Args().Single()); Assert.Equal("Reporter value 'foo' is invalid. Available reporters: switch1, switch2", eventArgs.Message); }
public void CallsExecuteAssemblyOnceForEachAssembly() { var visitor = new XmlTestExecutionVisitor(null, null); visitor.Finished.Set(); var assm1 = new TaskItem(@"C:\Full\Path\1"); var assm2 = new TaskItem(@"C:\Full\Path\2", new Dictionary<string, string> { { "ConfigFile", @"C:\Config\File" } }); var xunit = new Testable_xunit { CreateVisitor_Result = visitor }; xunit.Assemblies = new ITaskItem[] { assm1, assm2 }; xunit.Execute(); Assert.Collection(xunit.ExecuteAssembly_Calls, call => Assert.Equal(@"C:\Full\Path\1, (null)", call), call => Assert.Equal(@"C:\Full\Path\2, C:\Config\File", call) ); }
public static void RunsDiscoveredTests() { var xunit = new Testable_xunit(); xunit.DiscoveryTestCases.Add(Substitute.For <ITestCase>()); var runTestCases = new List <ITestCase>(); xunit.FrontController.WhenAny(fc => fc.RunTests((IEnumerable <ITestCase>)null, null, null)) .Do(callInfo => { runTestCases.AddRange((IEnumerable <ITestCase>)callInfo[0]); }); xunit._ExecuteAssembly("assemblyFilename", "configFilename"); Assert.Equal(xunit.DiscoveryTestCases, runTestCases); }
public static void ReturnsFalseWhenFailCountIsNonZero() { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For <ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task } }; var result = xunit.Execute(); Assert.False(result); }
public static void CallsExecuteAssemblyOnceForEachAssembly() { var visitor = new XmlTestExecutionVisitor(null, null); visitor.Finished.Set(); var assm1 = new TaskItem(@"C:\Full\Path\1"); var assm2 = new TaskItem(@"C:\Full\Path\2", new Dictionary <string, string> { { "ConfigFile", @"C:\Config\File" } }); var xunit = new Testable_xunit { CreateVisitor_Result = visitor }; xunit.Assemblies = new ITaskItem[] { assm1, assm2 }; xunit.Execute(); Assert.Collection(xunit.ExecuteAssembly_Calls, call => Assert.Equal(@"C:\Full\Path\1, (null)", call), call => Assert.Equal(@"C:\Full\Path\2, C:\Config\File", call) ); }
public static void ChangesCurrentDirectoryWhenWorkingFolderIsNotNull() { var tempFolder = Environment.GetEnvironmentVariable("TEMP") ?? Environment.GetEnvironmentVariable("TMP") ?? Environment.GetEnvironmentVariable("TMPDIR") ?? "/tmp"; tempFolder = Path.GetFullPath(tempFolder); // Ensure that the 8.3 path is not used // For macOS compatibility, switch to the folder and then get it, because the temp folder // is usually under /var/folders/... which is softlinked to /private/var/folders var originalDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(tempFolder); tempFolder = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(originalDirectory); var xunit = new Testable_xunit { WorkingFolder = tempFolder }; xunit.Execute(); var actual = Directory.GetCurrentDirectory(); var expected = tempFolder; if (actual[actual.Length - 1] != Path.DirectorySeparatorChar) { actual += Path.DirectorySeparatorChar; } if (expected[expected.Length - 1] != Path.DirectorySeparatorChar) { expected += Path.DirectorySeparatorChar; } Assert.Equal(expected, actual); }
public static void ReturnsFalseWhenFailCountIsNonZero() { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For<ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task } }; xunit.DiscoveryTestCases.Add(Mocks.TestCase()); var result = xunit.Execute(); Assert.False(result); }
public static void WritesXmlV1ToDisk() { var tempFile = Path.GetTempFileName(); try { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For<ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xmlTaskItem = Substitute.For<ITaskItem>(); xmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, XmlV1 = xmlTaskItem }; xunit.Execute(); new XmlDocument().Load(tempFile); // File should exist as legal XML } finally { File.Delete(tempFile); } }
public static void WritesHtmlToDisk() { var tempFile = Path.GetTempFileName(); File.Delete(tempFile); try { var visitor = new XmlTestExecutionVisitor(null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For<ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var htmlTaskItem = Substitute.For<ITaskItem>(); htmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, Html = htmlTaskItem }; xunit.Execute(); Assert.True(File.Exists(tempFile)); } finally { File.Delete(tempFile); } }
public void NoExplicitReporter_NoEnvironmentallyEnabledReporters_UsesDefaultReporter() { var implicitReporter = Mocks.RunnerReporter(isEnvironmentallyEnabled: false); var xunit = new Testable_xunit(); xunit.AvailableReporters.Add(implicitReporter); var reporter = xunit.GetReporter(); Assert.IsType<DefaultRunnerReporterWithTypes>(reporter); }
public void BadChosenReporter_NoAvailableReporters() { var xunit = new Testable_xunit { Reporter = "foo" }; var reporter = xunit.GetReporter(); Assert.Null(reporter); var eventArgs = Assert.IsType<BuildErrorEventArgs>(xunit.BuildEngine.Captured(x => x.LogErrorEvent(null)).Args().Single()); Assert.Equal("Reporter value 'foo' is invalid. There are no available reporters.", eventArgs.Message); }
public static void DiscoversAllTestsInAssembly() { var xunit = new Testable_xunit(); xunit._ExecuteAssembly("assemblyFilename", "configFilename"); xunit.FrontController.Received().Find(false, Arg.Any<IMessageSink>(), Arg.Any<ITestFrameworkDiscoveryOptions>()); }
public static void RunsDiscoveredTests() { var xunit = new Testable_xunit(); xunit.DiscoveryTestCases.Add(Substitute.For<ITestCase>()); var runTestCases = new List<ITestCase>(); xunit.FrontController.WhenAny(fc => fc.RunTests((IEnumerable<ITestCase>)null, null, null)) .Do(callInfo => { runTestCases.AddRange((IEnumerable<ITestCase>)callInfo[0]); }); xunit._ExecuteAssembly("assemblyFilename", "configFilename"); Assert.Equal(xunit.DiscoveryTestCases, runTestCases); }
public static void DoesNotRunFilteredTests() { var xunit = new Testable_xunit { ExcludeTraits = "One=1" }; var testCase1 = Substitute.For<ITestCase>(); testCase1.Traits.Returns(new Dictionary<string, List<string>>()); xunit.DiscoveryTestCases.Add(testCase1); var testCase2 = Substitute.For<ITestCase>(); testCase2.Traits.Returns(new Dictionary<string, List<string>> { { "One", new List<string> { "1" } } }); xunit.DiscoveryTestCases.Add(testCase2); var runTestCases = new List<ITestCase>(); xunit.FrontController.WhenAny(fc => fc.RunTests((IEnumerable<ITestCase>)null, null, null)) .Do(callInfo => { runTestCases.AddRange((IEnumerable<ITestCase>)callInfo[0]); }); xunit._ExecuteAssembly("assembyFileName", "configFilename"); Assert.Equal(1, runTestCases.Count); Assert.Contains(testCase1, runTestCases); Assert.DoesNotContain(testCase2, runTestCases); }
public void LogsAssemblyMessage() { var xunit = new Testable_xunit(); xunit._ExecuteAssembly("assemblyFilename", "configFilename"); xunit.BuildEngine.Received().LogMessageEvent(Arg.Is<BuildMessageEventArgs>(bmea => ValidateAssemblyBanner(bmea))); }
public void RunsDiscoveredTests() { var xunit = new Testable_xunit(); var runTestCases = new List<ITestCase>(); xunit.FrontController.WhenAny(fc => fc.Run(null, null)) .Do(callInfo => { runTestCases.AddRange((IEnumerable<ITestCase>)callInfo[0]); ((IMessageSink)callInfo[1]).OnMessage(new TestAssemblyFinished()); }); xunit._ExecuteAssembly("assemblyFilename", "configFilename"); Assert.Equal(xunit.DiscoveryTestCases, runTestCases); }
public void WritesXmlToDisk() { var tempFile = Path.GetTempFileName(); try { var visitor = new MSBuildVisitor(null, null, null) { Failed = 1 }; visitor.Finished.Set(); var task = Substitute.For<ITaskItem>(); task.GetMetadata("FullPath").Returns("C:\\Full\\Path\\Name.dll"); var xmlTaskItem = Substitute.For<ITaskItem>(); xmlTaskItem.GetMetadata("FullPath").Returns(tempFile); var xunit = new Testable_xunit { CreateVisitor_Result = visitor, Assemblies = new[] { task }, Xml = xmlTaskItem }; xunit.Execute(); Assert.DoesNotThrow(() => new XmlDocument().Load(tempFile)); } finally { File.Delete(tempFile); } }
public void BadChosenReporter_WithAvailableReporters() { var xunit = new Testable_xunit { Reporter = "foo" }; xunit.AvailableReporters.AddRange(new[] { Mocks.RunnerReporter("switch1"), Mocks.RunnerReporter("switch2") }); var reporter = xunit.GetReporter(); Assert.Null(reporter); var eventArgs = Assert.IsType<BuildErrorEventArgs>(xunit.BuildEngine.Captured(x => x.LogErrorEvent(null)).Args().Single()); Assert.Equal("Reporter value 'foo' is invalid. Available reporters: switch1, switch2", eventArgs.Message); }
public void WithEnvironmentalOverride_WithEnvironmentalOverridesDisabled_UsesDefaultReporter() { var implicitReporter = Mocks.RunnerReporter(isEnvironmentallyEnabled: true); var xunit = new Testable_xunit { NoAutoReporters = true }; xunit.AvailableReporters.Add(implicitReporter); var reporter = xunit.GetReporter(); Assert.IsType<DefaultRunnerReporterWithTypes>(reporter); }
public void NoReporters_UsesDefaultReporter() { var xunit = new Testable_xunit(); var reporter = xunit.GetReporter(); Assert.IsType<DefaultRunnerReporterWithTypes>(reporter); }
public void ErrorsDuringExecutionAreLogged() { var exception = new DivideByZeroException(); var xunit = new Testable_xunit { CreateFrontController_Exception = exception }; var messages = new List<string>(); xunit._ExecuteAssembly("assemblyFilename", "configFilename"); xunit.BuildEngine.Received().LogErrorEvent(Arg.Is<BuildErrorEventArgs>(beea => CaptureErrorMessage(beea, messages))); Assert.Equal("System.DivideByZeroException: Attempted to divide by zero.", messages[0]); }