Example #1
0
        public static void CurrentDomainUnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
        {
            var message = getException((Exception)args.ExceptionObject);
            var result  = new TestResult("Any", "", "", 0, "An unhandled exception was thrown while running a test", TestState.Panic, message);

            AddResults(result);
            var writer = new ResultsXmlWriter(_results);

            writer.Write(_arguments.OutputFile);
            if (args.IsTerminating)
            {
                Environment.Exit(-1);
            }
        }
Example #2
0
        public static void CurrentDomainUnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
        {
            var message = getException((Exception)args.ExceptionObject);

            // TODO: Seriously!? Firgure out what thread is causing the app domain unload exception
            // Yeah, seriously. When user code throws background exceptions we want them to know.
            if (!_arguments.CompatabilityMode && !args.ExceptionObject.GetType().Equals(typeof(System.AppDomainUnloadedException)))
            {
                var finalOutput = new TestResult("Any", "", "", 0, "An unhandled exception was thrown while running a test.", TestState.Panic,
                                                 "This is usually caused by a background thread throwing an unhandled exception. " +
                                                 "Most test runners run in clr 1 mode which hides these exceptions from you. If you still want to suppress these errors (not recommended) you can enable compatibility mode." + Environment.NewLine + Environment.NewLine +
                                                 "To head on to happy land where fluffy bunnies roam freely painting green left right and center do so by passing the --compatibility-mode switch to the test " +
                                                 "runner or set the <TestRunnerCompatibilityMode>true</TestRunnerCompatibilityMode> configuration option in " +
                                                 "AutoTest.Net." + Environment.NewLine + Environment.NewLine + message);
                AddResults(finalOutput);
            }

            if (args.IsTerminating)
            {
                var writer = new ResultsXmlWriter(_results);
                writer.Write(_arguments.OutputFile);
                Write(" ");
                if (File.Exists(_arguments.OutputFile))
                {
                    Write("Test run result:");
                    Write(File.ReadAllText(_arguments.OutputFile));
                }
                Environment.Exit(-1);
            }

            Thread.CurrentThread.IsBackground = true;
            Thread.CurrentThread.Name         = "Dead thread";
            lock (_haltedThreads)
            {
                _haltedThreads.Add(Thread.CurrentThread);
            }

            /*if (Thread.CurrentThread.ManagedThreadId != _mainThreadID)
             * {
             *  while (true)
             *      Thread.Sleep(TimeSpan.FromHours(1));
             * }*/
        }
Example #3
0
        public void Should_write_result()
        {
            var result = new List <TestResult>();

            result.Add(new TestResult("nunit", @"C:\Users\ack\src\AutoTest.Net\src\AutoTest.Runners.NUnit.Tests.TestResource\bin\AutoTest.NET\AutoTest.Runners.NUnit.Tests.TestResource.dll",
                                      "AutoTest.Runners.NUnit.Tests.TestResource.Fixture1", 100, "AutoTest.Runners.NUnit.Tests.TestResource.Fixture1.Should_fail", Shared.Results.TestState.Failed,
                                      "failing test"));
            result[0].AddStackLine(new StackLine()
            {
                Method = "AutoTest.Runners.NUnit.Tests.TestResource.Fixture1.Should_fail()",
                File   = @"C:\Users\ack\src\AutoTest.Net\src\AutoTest.Runners.NUnit.Tests.TestResource\Fixture1.cs", Line = 21
            });

            result.Add(new TestResult("nunit", @"C:\Users\ack\src\AutoTest.Net\src\AutoTest.Runners.NUnit.Tests.TestResource\bin\AutoTest.NET\AutoTest.Runners.NUnit.Tests.TestResource.dll",
                                      "AutoTest.Runners.NUnit.Tests.TestResource.Fixture1", 20, "AutoTest.Runners.NUnit.Tests.TestResource.Fixture1.Should_ignore", Shared.Results.TestState.Ignored,
                                      "ignored test"));
            result[1].AddStackLine(new StackLine()
            {
                Method = "AutoTest.Runners.NUnit.Tests.TestResource.Fixture1.Should_ignore()",
                File   = @"C:\Users\ack\src\AutoTest.Net\src\AutoTest.Runners.NUnit.Tests.TestResource\Fixture1.cs", Line = 27
            });

            result.Add(new TestResult("nunit", @"C:\Users\ack\src\AutoTest.Net\src\AutoTest.Runners.NUnit.Tests.TestResource\bin\AutoTest.NET\AutoTest.Runners.NUnit.Tests.TestResource.dll",
                                      "AutoTest.Runners.NUnit.Tests.TestResource.Fixture1", 20, "AutoTest.Runners.NUnit.Tests.TestResource.Fixture1.Should_pass", Shared.Results.TestState.Passed, ""));

            result.Add(new TestResult("nunit", @"C:\Users\ack\src\AutoTest.Net\src\AutoTest.Runners.NUnit.Tests.TestResource\bin\AutoTest.NET\AutoTest.Runners.NUnit.Tests.TestResource.dll",
                                      "AutoTest.Runners.NUnit.Tests.TestResource.Fixture2", 20, "AutoTest.Runners.NUnit.Tests.TestResource.Fixture2.Should_also_pass", Shared.Results.TestState.Passed, ""));

            result.Add(new TestResult("nunit", @"C:\Users\ack\src\AutoTest.Net\src\AutoTest.Runners.NUnit.Tests.TestResource\bin\AutoTest.NET\AutoTest.Runners.NUnit.Tests.TestResource.dll",
                                      "AutoTest.Runners.NUnit.Tests.TestResource.Fixture2", 250, "AutoTest.Runners.NUnit.Tests.TestResource.Fixture2.Should_also_pass_again", "Alternative description", Shared.Results.TestState.Passed, ""));

            var file   = Path.GetTempFileName();
            var writer = new ResultsXmlWriter(result);

            writer.Write(file);

            var original  = File.ReadAllText(file).Replace("\r\n", "\n");
            var generated = File.ReadAllText(getPath("Results.xml")).Replace("\r\n", "\n");

            Assert.That(original, Is.EqualTo(generated));
        }
Example #4
0
        private static void tryRunTests()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledExceptionHandler;
            var junction = new PipeJunction(_arguments.Channel);

            try
            {
                var parser = new OptionsXmlReader(_arguments.InputFile);
                parser.Parse();
                if (!parser.IsValid)
                {
                    return;
                }

                run(parser, junction);

                var writer = new ResultsXmlWriter(_results);
                writer.Write(_arguments.OutputFile);
            }
            catch (Exception ex)
            {
                try
                {
                    var result = new List <TestResult>();
                    result.Add(ErrorHandler.GetError("Init", ex));
                    var writer = new ResultsXmlWriter(result);
                    writer.Write(_arguments.OutputFile);
                }
                catch
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            finally
            {
                junction = null;
            }
        }