コード例 #1
0
 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);
     }
 }
コード例 #2
0
        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();
        }
コード例 #3
0
ファイル: Driver.cs プロジェクト: dczupek/Formatting
        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;
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: EchoProgram.cs プロジェクト: soelske/mbunit-v3
        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);
        }
コード例 #6
0
ファイル: SampleRunner.cs プロジェクト: citizenmatt/gallio
        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);
                }
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
 /// <exclude />
 /// <summary>
 /// Provided so that the unit tests can override test execution behavior.
 /// </summary>
 protected virtual TestLauncherResult RunLauncher(TestLauncher launcher)
 {
     return launcher.Run();
 }
コード例 #9
0
ファイル: GallioTask.cs プロジェクト: still-adam-k/mbunit-v3
 /// <exclude />
 /// <summary>
 /// Provided so that the unit tests can override test execution behavior.
 /// </summary>
 protected virtual TestLauncherResult RunLauncher(TestLauncher launcher)
 {
     return(launcher.Run());
 }
コード例 #10
0
        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);
                }
            }
        }
コード例 #11
0
 /// <summary>
 /// Provided so that the unit tests can override test execution behavior.
 /// </summary>
 internal virtual TestLauncherResult RunLauncher(TestLauncher launcher)
 {
     return(launcher.Run());
 }
コード例 #12
0
 /// <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);
                }
            }
        }
コード例 #14
0
        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);
                }
            }
        }