public static void Main() { using (TextWriter tw = new StreamWriter("RunTests.log")) { var logger = new TextLogger(tw); RuntimeBootstrap.Initialize(new RuntimeSetup(), logger); TestLauncher launcher = new TestLauncher(); launcher.AddFilePattern("RunTests.exe"); TestLauncherResult result = launcher.Run(); Console.WriteLine(result.ResultSummary); } }
private void RunTests(IRunContext runContext, IFrameworkHandle testExecutionRecorder) { if (runContext.InIsolation) { launcher.TestProject.TestRunnerFactoryName = StandardTestRunnerFactoryNames.IsolatedAppDomain; } var extension = new VSTestWindowExtension(testExecutionRecorder, testCaseFactory, testResultFactory); launcher.TestProject.AddTestRunnerExtension(extension); launcher.Run(); }
public static int Main() { NativeConsole console = NativeConsole.Instance; var launcher = new TestLauncher { EchoResults = true, Logger = new FilteredLogger(new RichConsoleLogger(console), Verbosity.Normal), ProgressMonitorProvider = new RichConsoleProgressMonitorProvider(console), RuntimeSetup = new RuntimeSetup(), TestProject = { TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local } }; string gallioBin = Environment.GetEnvironmentVariable(GallioBinEnvironmentVariable) ?? InstallationConfiguration.LoadFromRegistry().InstallationFolder; if(string.IsNullOrEmpty(gallioBin)) { Console.Error.WriteLine("Cannot find Gallio installation directory."); Console.Error.WriteLine("Specify it with \"{0}\" environment variable.", GallioBinEnvironmentVariable); return 1; } launcher.AddFilePattern(typeof(Driver).Assembly.Location); launcher.RuntimeSetup.AddPluginDirectory(gallioBin); TestLauncherResult result = launcher.Run(); ConsoleColor originalConsoleColor = console.ForegroundColor; console.ForegroundColor = result.ResultCode == ResultCode.Success ? ConsoleColor.DarkGreen : ConsoleColor.Red; console.WriteLine(); console.WriteLine(result.ResultSummary); console.WriteLine(); console.ForegroundColor = originalConsoleColor; if (result.ResultCode != ResultCode.Success && Debugger.IsAttached) { Debugger.Break(); } return result.ResultCode; }
public static int Main() { NativeConsole console = NativeConsole.Instance; var launcher = new TestLauncher { EchoResults = true, Logger = new FilteredLogger(new RichConsoleLogger(console), Verbosity.Normal), ProgressMonitorProvider = new RichConsoleProgressMonitorProvider(console), RuntimeSetup = new RuntimeSetup(), TestProject = { TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local } }; string gallioBin = Environment.GetEnvironmentVariable(GallioBinEnvironmentVariable) ?? InstallationConfiguration.LoadFromRegistry().InstallationFolder; if (string.IsNullOrEmpty(gallioBin)) { Console.Error.WriteLine("Cannot find Gallio installation directory."); Console.Error.WriteLine("Specify it with \"{0}\" environment variable.", GallioBinEnvironmentVariable); return(1); } launcher.AddFilePattern(typeof(Driver).Assembly.Location); launcher.RuntimeSetup.AddPluginDirectory(gallioBin); TestLauncherResult result = launcher.Run(); ConsoleColor originalConsoleColor = console.ForegroundColor; console.ForegroundColor = result.ResultCode == ResultCode.Success ? ConsoleColor.DarkGreen : ConsoleColor.Red; console.WriteLine(); console.WriteLine(result.ResultSummary); console.WriteLine(); console.ForegroundColor = originalConsoleColor; if (result.ResultCode != ResultCode.Success && Debugger.IsAttached) { Debugger.Break(); } return(result.ResultCode); }
private int RunTests(ILogger logger) { logger.Log(LogSeverity.Debug, Arguments.ToString()); var launcher = new TestLauncher { Logger = logger, ProgressMonitorProvider = CreateProgressMonitorProvider() }; ConfigureLauncherFromArguments(launcher, Arguments); TestLauncherResult result = launcher.Run(); DisplayResultSummary(result); return(result.ResultCode); }
private void Launch(bool doNoRun) { MarkupStreamWriter logStreamWriter = TestLog.Default; var launcher = new TestLauncher(); launcher.TestProject.TestPackage = testPackage; launcher.Logger = new MarkupStreamLogger(logStreamWriter); launcher.TestExecutionOptions.FilterSet = new FilterSet <ITestDescriptor>(new OrFilter <ITestDescriptor>(filters)); launcher.TestProject.TestRunnerFactoryName = TestRunnerFactoryName; string reportDirectory = SpecialPathPolicy.For <SampleRunner>().GetTempDirectory().FullName; launcher.TestProject.ReportDirectory = reportDirectory; launcher.TestProject.ReportNameFormat = "SampleRunnerReport"; launcher.ReportFormatterOptions.AddProperty(@"SaveAttachmentContents", @"false"); launcher.AddReportFormat(@"Text"); // Disabled because the Xml can get really big and causes problems if the sample runner is used frequently. //launcher.AddReportFormat("Xml"); launcher.DoNotRun = doNoRun; GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => launcher.TestRunnerOptions.AddProperty(x.Key, x.Value)); using (logStreamWriter.BeginSection("Log Output")) result = launcher.Run(); using (logStreamWriter.BeginSection("Text Report")) { foreach (string reportPath in result.ReportDocumentPaths) { string extension = Path.GetExtension(reportPath); if (extension == ".txt") { logStreamWriter.WriteLine(File.ReadAllText(reportPath)); } else if (extension == ".xml") { logStreamWriter.Container.AttachXml(null, File.ReadAllText(reportPath)); } File.Delete(reportPath); } } }
private void RunTests(ITestExecutionRecorder testExecutionRecorder) { TestLauncherResult testLauncherResult = _launcher.Run(); foreach (var allTestStepRun in testLauncherResult.Report.TestPackageRun.AllTestStepRuns) { TestCase tc = new TestCase(allTestStepRun.Step.FullName, new Uri(ExecutorUri)); ObjectModel.TestResult testResult = new ObjectModel.TestResult(tc); testResult.DisplayName = allTestStepRun.Step.FullName; testResult.ErrorLineNumber = allTestStepRun.Step.CodeLocation.Line; //testResult.ErrorStackTrace testResult.StartTime = allTestStepRun.StartTime; //testResult.ErrorMessage -- why this and messages? testResult.EndTime = allTestStepRun.EndTime; //testResult.Attachments = allTestStepRun.TestLog.Attachments; -- can I append my own? testResult.Duration = allTestStepRun.Result.Duration; //testResult.Messages = var testStatus = allTestStepRun.Result.Outcome.Status; switch (testStatus) { case TestStatus.Passed: testResult.Outcome = ObjectModel.TestOutcome.Passed; break; case TestStatus.Failed: testResult.Outcome = ObjectModel.TestOutcome.Failed; break; case TestStatus.Skipped: testResult.Outcome = ObjectModel.TestOutcome.Skipped; break; case TestStatus.Inconclusive: //is this right to use not found? testResult.Outcome = ObjectModel.TestOutcome.Skipped; break; } testExecutionRecorder.RecordResult(testResult); } }
/// <exclude /> /// <summary> /// Provided so that the unit tests can override test execution behavior. /// </summary> protected virtual TestLauncherResult RunLauncher(TestLauncher launcher) { return launcher.Run(); }
/// <exclude /> /// <summary> /// Provided so that the unit tests can override test execution behavior. /// </summary> protected virtual TestLauncherResult RunLauncher(TestLauncher launcher) { return(launcher.Run()); }
private void Launch(bool doNoRun) { MarkupStreamWriter logStreamWriter = TestLog.Default; var launcher = new TestLauncher(); launcher.TestProject.TestPackage = testPackage; launcher.Logger = new MarkupStreamLogger(logStreamWriter); launcher.TestExecutionOptions.FilterSet = new FilterSet<ITestDescriptor>(new OrFilter<ITestDescriptor>(filters)); launcher.TestProject.TestRunnerFactoryName = TestRunnerFactoryName; string reportDirectory = SpecialPathPolicy.For<SampleRunner>().GetTempDirectory().FullName; launcher.TestProject.ReportDirectory = reportDirectory; launcher.TestProject.ReportNameFormat = "SampleRunnerReport"; launcher.ReportFormatterOptions.AddProperty(@"SaveAttachmentContents", @"false"); launcher.AddReportFormat(@"Text"); // Disabled because the Xml can get really big and causes problems if the sample runner is used frequently. //launcher.AddReportFormat("Xml"); launcher.DoNotRun = doNoRun; GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => launcher.TestRunnerOptions.AddProperty(x.Key, x.Value)); using (logStreamWriter.BeginSection("Log Output")) result = launcher.Run(); using (logStreamWriter.BeginSection("Text Report")) { foreach (string reportPath in result.ReportDocumentPaths) { string extension = Path.GetExtension(reportPath); if (extension == ".txt") { logStreamWriter.WriteLine(File.ReadAllText(reportPath)); } else if (extension == ".xml") { logStreamWriter.Container.AttachXml(null, File.ReadAllText(reportPath)); } File.Delete(reportPath); } } }
/// <summary> /// Provided so that the unit tests can override test execution behavior. /// </summary> internal virtual TestLauncherResult RunLauncher(TestLauncher launcher) { return(launcher.Run()); }
/// <summary> /// Provided so that the unit tests can override test execution behavior. /// </summary> internal virtual TestLauncherResult RunLauncher(TestLauncher launcher) { return launcher.Run(); }
public void GeneratesNCoverCoverageWithCorrectOptionsAndMergesIfNecessary(string factoryName, NCoverVersion version, string ncoverCoverageFile, bool includeLogArgument, bool runMultipleAssemblies) { string tempPath = SpecialPathPolicy.For<NCoverTestIsolationProviderIntegrationTest>().GetTempDirectory().FullName; string coverageFilePath = Path.Combine(tempPath, ncoverCoverageFile ?? "Coverage.xml"); string coverageLogFilePath = Path.Combine(tempPath, "CoverageLog.txt"); string ncoverArguments = includeLogArgument ? "//l \"" + coverageLogFilePath + "\"" + (version == NCoverVersion.V1 ? "" : " //ll Normal") : null; if (File.Exists(coverageFilePath)) File.Delete(coverageFilePath); if (File.Exists(coverageLogFilePath)) File.Delete(coverageLogFilePath); Type firstTestType = typeof(SimpleTest); Type secondTestType = typeof(DummyTest); TestLauncher launcher = new TestLauncher(); launcher.Logger = new MarkupStreamLogger(TestLog.Default); launcher.TestProject.TestPackage.AddFile(new FileInfo(AssemblyUtils.GetAssemblyLocalPath(firstTestType.Assembly))); if (runMultipleAssemblies) launcher.TestProject.TestPackage.AddFile(new FileInfo(AssemblyUtils.GetAssemblyLocalPath(secondTestType.Assembly))); launcher.TestProject.TestRunnerFactoryName = factoryName; launcher.TestExecutionOptions.FilterSet = new FilterSet<ITestDescriptor>( new OrFilter<ITestDescriptor>(new[] { new TypeFilter<ITestDescriptor>(new EqualityFilter<string>(firstTestType.FullName), false), new TypeFilter<ITestDescriptor>(new EqualityFilter<string>(secondTestType.FullName), false), })); if (ncoverArguments != null) launcher.TestRunnerOptions.AddProperty("NCoverArguments", ncoverArguments); if (ncoverCoverageFile != null) launcher.TestRunnerOptions.AddProperty("NCoverCoverageFile", ncoverCoverageFile); TestLauncherResult result; using (new CurrentDirectorySwitcher(tempPath)) result = launcher.Run(); NCoverTool tool = NCoverTool.GetInstance(version, ProcessorArchitecture.MSIL); if (! tool.IsInstalled()) { Assert.AreEqual(ResultCode.Failure, result.ResultCode); var logEntries = result.Report.LogEntries; Assert.AreEqual(1, logEntries.Count, "Expected to find a log entry."); Assert.AreEqual(LogSeverity.Error, logEntries[0].Severity); Assert.Contains(logEntries[0].Details, tool.Name + " does not appear to be installed."); } else { int passed = runMultipleAssemblies ? 2 : 1; int failed = 1; Assert.AreEqual(passed + failed, result.Statistics.RunCount); Assert.AreEqual(passed, result.Statistics.PassedCount); Assert.AreEqual(failed, result.Statistics.FailedCount); Assert.AreEqual(0, result.Statistics.InconclusiveCount); Assert.AreEqual(0, result.Statistics.SkippedCount); Assert.IsTrue(File.Exists(coverageFilePath), "The NCover runner should have written its coverage log to '{0}'.", coverageFilePath); string coverageXml = File.ReadAllText(coverageFilePath); File.Delete(coverageFilePath); Assert.Contains(coverageXml, firstTestType.Name, "Expected the coverage log to include information about the test method that we actually ran.\n" + "In NCover v3, there is now a list of excluded 'system assemblies' in NCover.Console.exe.config which " + "specifies MbUnit and Gallio by default. For this test to run, the file must be edited such that " + "these entries are removed."); if (runMultipleAssemblies) { Assert.Contains(coverageXml, secondTestType.Name, "Expected the coverage log to include information about the test method that we actually ran.\n" + "In NCover v3, there is now a list of excluded 'system assemblies' in NCover.Console.exe.config which " + "specifies MbUnit and Gallio by default. For this test to run, the file must be edited such that " + "these entries are removed."); } if (ncoverArguments != null && ncoverArguments.Contains("/l")) { Assert.IsTrue(File.Exists(coverageLogFilePath), "Should have created a coverage log file since the /l argument was specified."); File.Delete(coverageLogFilePath); } } }
public void GeneratesNCoverCoverageWithCorrectOptionsAndMergesIfNecessary(string factoryName, NCoverVersion version, string ncoverCoverageFile, bool includeLogArgument, bool runMultipleAssemblies) { string tempPath = SpecialPathPolicy.For <NCoverTestIsolationProviderIntegrationTest>().GetTempDirectory().FullName; string coverageFilePath = Path.Combine(tempPath, ncoverCoverageFile ?? "Coverage.xml"); string coverageLogFilePath = Path.Combine(tempPath, "CoverageLog.txt"); string ncoverArguments = includeLogArgument ? "//l \"" + coverageLogFilePath + "\"" + (version == NCoverVersion.V1 ? "" : " //ll Normal") : null; if (File.Exists(coverageFilePath)) { File.Delete(coverageFilePath); } if (File.Exists(coverageLogFilePath)) { File.Delete(coverageLogFilePath); } Type firstTestType = typeof(SimpleTest); Type secondTestType = typeof(DummyTest); TestLauncher launcher = new TestLauncher(); launcher.Logger = new MarkupStreamLogger(TestLog.Default); launcher.TestProject.TestPackage.AddFile(new FileInfo(AssemblyUtils.GetAssemblyLocalPath(firstTestType.Assembly))); if (runMultipleAssemblies) { launcher.TestProject.TestPackage.AddFile(new FileInfo(AssemblyUtils.GetAssemblyLocalPath(secondTestType.Assembly))); } launcher.TestProject.TestRunnerFactoryName = factoryName; launcher.TestExecutionOptions.FilterSet = new FilterSet <ITestDescriptor>( new OrFilter <ITestDescriptor>(new[] { new TypeFilter <ITestDescriptor>(new EqualityFilter <string>(firstTestType.FullName), false), new TypeFilter <ITestDescriptor>(new EqualityFilter <string>(secondTestType.FullName), false), })); if (ncoverArguments != null) { launcher.TestRunnerOptions.AddProperty("NCoverArguments", ncoverArguments); } if (ncoverCoverageFile != null) { launcher.TestRunnerOptions.AddProperty("NCoverCoverageFile", ncoverCoverageFile); } TestLauncherResult result; using (new CurrentDirectorySwitcher(tempPath)) result = launcher.Run(); NCoverTool tool = NCoverTool.GetInstance(version, ProcessorArchitecture.MSIL); if (!tool.IsInstalled()) { Assert.AreEqual(ResultCode.Failure, result.ResultCode); var logEntries = result.Report.LogEntries; Assert.AreEqual(1, logEntries.Count, "Expected to find a log entry."); Assert.AreEqual(LogSeverity.Error, logEntries[0].Severity); Assert.Contains(logEntries[0].Details, tool.Name + " does not appear to be installed."); } else { int passed = runMultipleAssemblies ? 2 : 1; int failed = 1; Assert.AreEqual(passed + failed, result.Statistics.RunCount); Assert.AreEqual(passed, result.Statistics.PassedCount); Assert.AreEqual(failed, result.Statistics.FailedCount); Assert.AreEqual(0, result.Statistics.InconclusiveCount); Assert.AreEqual(0, result.Statistics.SkippedCount); Assert.IsTrue(File.Exists(coverageFilePath), "The NCover runner should have written its coverage log to '{0}'.", coverageFilePath); string coverageXml = File.ReadAllText(coverageFilePath); File.Delete(coverageFilePath); Assert.Contains(coverageXml, firstTestType.Name, "Expected the coverage log to include information about the test method that we actually ran.\n" + "In NCover v3, there is now a list of excluded 'system assemblies' in NCover.Console.exe.config which " + "specifies MbUnit and Gallio by default. For this test to run, the file must be edited such that " + "these entries are removed."); if (runMultipleAssemblies) { Assert.Contains(coverageXml, secondTestType.Name, "Expected the coverage log to include information about the test method that we actually ran.\n" + "In NCover v3, there is now a list of excluded 'system assemblies' in NCover.Console.exe.config which " + "specifies MbUnit and Gallio by default. For this test to run, the file must be edited such that " + "these entries are removed."); } if (ncoverArguments != null && ncoverArguments.Contains("/l")) { Assert.IsTrue(File.Exists(coverageLogFilePath), "Should have created a coverage log file since the /l argument was specified."); File.Delete(coverageLogFilePath); } } }