Пример #1
0
        public TestResult RunTests()
        {
            _totalTests = 0;

            _testsFailed = 0;

            using (finished = new ManualResetEvent(false))
                using (AssemblyRunner runner = AssemblyRunner.WithoutAppDomain(_assemblyFileName))
                {
                    runner.OnExecutionComplete = TestAssemblyExecutionFinished;

                    runner.Start();

                    finished.WaitOne();

                    while (runner.Status != AssemblyRunnerStatus.Idle)
                    {
                        Thread.Sleep(500);
                    }
                }

            TestResult result = new TestResult {
                TotalTests = _totalTests, TestsFailed = _testsFailed
            };

            return(result);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            TestParentActivity = this;

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            listView = FindViewById <ListView>(Resource.Id.listView);

            adapter = new TestResultsAdapter {
                Parent = this
            };
            listView.Adapter = adapter;

            assemblyRunner = AssemblyRunner.WithoutAppDomain(Assembly.GetExecutingAssembly().GetName().Name + ".dll");
            assemblyRunner.OnDiscoveryComplete = DiscoveryCompleteHandler;;
            assemblyRunner.OnExecutionComplete = ExecutionCompleteHandler;;
            assemblyRunner.OnTestFailed        = TestFailedHandler;;
            assemblyRunner.OnTestSkipped       = TestSkippedHandler;
            assemblyRunner.OnTestPassed        = TestPassedHandler;
            assemblyRunner.OnTestOutput        = TestOutputHandler;

            Console.WriteLine("Discovering...");
            assemblyRunner.Start();
        }
Пример #3
0
        static async Task Main(string[] args)
        {
            MSBuildLocator.RegisterDefaults();

            var projectFilePath = @"C:\Code\AnalyzingSourceCodeUsingRoslyn\TestRunner.Exercise\TestRunner.Exercise.csproj";
            Process.Start("dotnet", $"restore {projectFilePath}").WaitForExit();

            var workspace = MSBuildWorkspace.Create();
            var project = await workspace.OpenProjectAsync(projectFilePath);
            
            var tests = project.Documents.Single(document => document.Name == "TestRunnerExerciseTests.cs");
            var root = await tests.GetSyntaxRootAsync();
            root = new UnskipTests().Visit(root);
            tests = tests.WithSyntaxRoot(root);

            var compilation = await tests.Project.GetCompilationAsync();
            var diagnostics = compilation.GetDiagnostics();
            var errors = diagnostics.Count(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error);
            Console.WriteLine($"Diagnostics: {diagnostics.Length}. Errors: {errors}");

            compilation.Emit(compilation.SourceModule.Name);

            Assembly.LoadFrom(compilation.SourceModule.Name);
            
            var finished = new ManualResetEventSlim();
            var runner = AssemblyRunner.WithoutAppDomain(compilation.SourceModule.Name);
            runner.OnTestFailed += info => Console.WriteLine($"[FAIL] {info.TestDisplayName}: {info.ExceptionMessage}");
            runner.OnTestPassed += info => Console.WriteLine($"[PASS] {info.TestDisplayName}");
            runner.OnTestSkipped += info => Console.WriteLine($"[SKIP] {info.TestDisplayName}");
            runner.OnExecutionComplete += info => finished.Set();
            
            runner.Start();
            finished.Wait();
        }
Пример #4
0
        static int Main(string[] args)
        {
            string testAssembly = typeof(Program).Assembly.Location;
            var    typeName     = args.Length == 2 ? args[1] : null;

            try
            {
                using (var runner = AssemblyRunner.WithoutAppDomain(testAssembly))
                {
                    runner.OnDiscoveryComplete = OnDiscoveryComplete;
                    runner.OnExecutionComplete = OnExecutionComplete;
                    runner.OnTestFailed        = OnTestFailed;
                    runner.OnTestSkipped       = OnTestSkipped;

                    Console.WriteLine("Discovering...");
                    runner.Start(typeName);

                    finished.WaitOne();
                    finished.Dispose();
                }
            }
            catch (InvalidOperationException)
            {
                // Swallow
            }

            return(result);
        }
Пример #5
0
        private static async Task Handler(int iterations, int duration, int concurrency, int rampUp, string reportFile,
                                          string target)
        {
            var reportWriter = new ReportWriter(reportFile);

            var userStepTime = rampUp / concurrency;
            var testTasks    = new List <Task>();
            var startTime    = DateTime.UtcNow;

            var testAssembly = System.Reflection.Assembly.LoadFrom(target);

            for (var i = 1; i <= concurrency; ++i)
            {
                var threadName    = $"worker_{i}";
                var eventListener = new XUnitTestEventListener(reportWriter, threadName);

                var runner = AssemblyRunner.WithoutAppDomain(target);
                runner.OnDiscoveryComplete = XUnitTestEventListener.OnDiscoveryComplete;

                runner.OnTestFailed   = eventListener.OnTestFailed;
                runner.OnTestSkipped  = eventListener.OnTestSkipped;
                runner.OnTestFinished = eventListener.OnTestFinished;

                testTasks.Add(Task.Run(() => StartWorker(runner, startTime, iterations, duration)));
                Thread.Sleep(userStepTime * 1000);
            }

            await Task.WhenAll(testTasks);

            await reportWriter.StopWritingAsync();
        }
Пример #6
0
        public static int Run(string assemblyPath, List <string> typeNames = null)
        {
            // Create a runner for the specifid assembly.
            using (AssemblyRunner runner = AssemblyRunner.WithoutAppDomain(assemblyPath))
            {
                // Start out assuming success; we'll set this to 1 if we get a failed test
                var result = new int[] { 0 };

                if (typeNames?.Count == 0)
                {
                    Run(runner, result, null);
                }
                else
                {
                    typeNames.ForEach(typeName => Run(runner, result, typeName));
                }

                // Wait for the assembly runner to go idle.
                using (var waitHandle = new ManualResetEvent(false))
                {
                    while (runner.Status != AssemblyRunnerStatus.Idle)
                    {
                        waitHandle.WaitOne(10);
                    }
                }

                // Return overall status.
                return(result[0]);
            }
        }
Пример #7
0
        /// <summary>   Runs the tests. </summary>
        /// <returns>   The Results of the test run. </returns>
        public TestRunnerResults Run()
        {
            var assembly = Assembly.LoadFrom(this.runnerSettings.TestAssemblyFullName);

            using var runner = AssemblyRunner.WithoutAppDomain(assembly.Location);

            runner.OnDiscoveryComplete = OnDiscoveryComplete;
            runner.OnExecutionComplete = OnExecutionComplete;
            runner.OnTestPassed        = OnTestPassed;
            runner.OnTestFailed        = OnTestFailed;
            runner.OnTestSkipped       = OnTestSkipped;
            runner.TestCaseFilter      =
                f => this.runnerSettings.TestsToRun.Any(
                    t => t.TestClassName == f.TestMethod.TestClass.Class.Name &&
                    t.TestName == f.TestMethod.Method.Name);

            Console.WriteLine("Discovering...");

            runner.Start(parallel: false);

            Finished.WaitOne();
            Finished.Dispose();

            return(new TestRunnerResults(true, TestRunnerType.XUnit));
        }
Пример #8
0
        static int Main(string[] args)
        {
            if (args.Length == 0 || args.Length > 2)
            {
                Console.WriteLine("usage: TestRunner <assembly> [typeName]");
                return(2);
            }

            var testAssembly = args[0];
            var typeName     = args.Length == 2 ? args[1] : null;

            using (var runner = AssemblyRunner.WithoutAppDomain(testAssembly))
            {
                runner.OnDiscoveryComplete = OnDiscoveryComplete;
                runner.OnExecutionComplete = OnExecutionComplete;
                runner.OnTestFailed        = OnTestFailed;
                runner.OnTestSkipped       = OnTestSkipped;

                Console.WriteLine("Discovering...");
                runner.Start(typeName);

                finished.WaitOne();
                finished.Dispose();

                return(result);
            }
        }
Пример #9
0
 private SimpleXUnit(string assemblyPath, TextWriter textWriter, bool verbose)
 {
     this.verbose    = verbose;
     this.textWriter = textWriter ?? Console.Out;
     assemblyRunner  = new Lazy <AssemblyRunner>(() =>
     {
         var percorsoAssemblyAttuale        = assemblyPath ?? Assembly.GetEntryAssembly().Location;
         var assemblyRunner                 = AssemblyRunner.WithoutAppDomain(percorsoAssemblyAttuale);
         assemblyRunner.OnTestFailed        = OnTestFailed;
         assemblyRunner.OnTestSkipped       = OnTestSkipped;
         assemblyRunner.OnTestPassed        = OnTestPassed;
         assemblyRunner.OnDiscoveryComplete = OnDiscoveryComplete;
         assemblyRunner.OnExecutionComplete = OnExecutionComplete;
         return(assemblyRunner);
     });
 }
Пример #10
0
        public static void Run(Assembly ass, string single, bool stopOnErrors, bool logToConsole = true)
        {
            Runner r = new Runner(AssemblyRunner.WithoutAppDomain(ass.Location));

            if (logToConsole)
            {
                Logger.SetDestination(new MyLogger());
            }

            r.strTest      = single;
            r.stopOnErrors = stopOnErrors;
            r.verbose      = logToConsole;

            r.Run();

            r.Dispose();
        }
Пример #11
0
        public static int Run()
        {
            using var runner           = AssemblyRunner.WithoutAppDomain(typeof(Runner).Assembly.Location);
            runner.OnDiscoveryComplete = OnDiscoveryComplete;
            runner.OnTestPassed        = OnTestPassed;
            runner.OnExecutionComplete = OnExecutionComplete;
            runner.OnTestFailed        = OnTestFailed;
            runner.OnTestSkipped       = OnTestSkipped;

            Console.WriteLine("Discovering...");

            runner.Start();

            Finished.WaitOne();
            Finished.Dispose();

            return(_result);
        }
Пример #12
0
        private static void RunTests(Assembly testAssembly)
        {
            _finished = new ManualResetEvent(false);

            // Run tests
            using var runner           = AssemblyRunner.WithoutAppDomain(testAssembly.Location);
            runner.OnDiscoveryComplete = OnDiscoveryComplete;
            runner.OnExecutionComplete = OnExecutionComplete;
            runner.OnTestFailed        = OnTestFailed;
            runner.OnTestPassed        = OnTestPassed;
            runner.OnTestSkipped       = OnTestSkipped;

            Log.Debug($"Processing {testAssembly.FullName}...");
            runner.Start();

            _finished.WaitOne();
            _finished.Dispose();
        }
Пример #13
0
        /// <summary>
        /// Runs the tests in the given assembly
        /// </summary>
        /// <param name="testAssembly">Assembly with XUnit tests</param>
        /// <returns>True if all tests passed</returns>
        public static bool Run(Assembly testAssembly)
        {
            bool allPass = true;
            var  runner  = AssemblyRunner.WithoutAppDomain(testAssembly.Location);

            runner.OnDiscoveryComplete = (info) =>
            {
                write($"Running {info.TestCasesToRun} of {info.TestCasesDiscovered} tests...");
            };

            runner.OnExecutionComplete = (info) =>
            {
                write($"Finished: {info.TotalTests} tests in {Math.Round(info.ExecutionTime, 3)}s ({info.TestsFailed} failed, {info.TestsSkipped} skipped)");
                finished.Set();
            };

            runner.OnTestPassed = (info) =>
            {
                writePass($"[PASS] {info.TestDisplayName}");
                var traits = info.Traits;
            };


            runner.OnTestFailed = (info) =>
            {
                writeFail($"[FAIL] {info.TestDisplayName}: {info.ExceptionMessage}");
                allPass = false;
            };

            runner.OnTestSkipped = (info) =>
            {
                writeWarning($"[SKIP] {info.TestDisplayName}: {info.SkipReason}");
                allPass = false;
            };

            write("Discovering Tests...");
            runner.Start();

            //pause this thread until tests are complete
            finished.WaitOne();
            finished.Dispose();

            return(allPass);
        }
Пример #14
0
        static void Main(string[] args)
        {
            string pathOfCurrentlyExecutingAssembly   = Assembly.GetExecutingAssembly().Location;
            string folderOfCurrentlyExecutingAssembly = Path.GetDirectoryName(pathOfCurrentlyExecutingAssembly);
            var    nameOfAssemblyToTest = $"{typeof(UnitTest1).Assembly.GetName().Name}.dll";
            var    testAssemblyToRun    = $"{folderOfCurrentlyExecutingAssembly}/{nameOfAssemblyToTest}";

            using AssemblyRunner runner = AssemblyRunner.WithoutAppDomain(testAssemblyToRun);
            runner.OnDiscoveryComplete  = OnDiscoveryComplete;
            runner.OnExecutionComplete  = OnExecutionComplete;
            runner.OnTestFailed         = OnTestFailed;
            runner.OnTestSkipped        = OnTestSkipped;

            System.Console.WriteLine("Discovering...");
            runner.Start();

            finished.WaitOne();
            finished.Dispose();
        }
Пример #15
0
        public string FunctionHandler(string input, ILambdaContext context)
        {
            var testAssembly = System.Reflection.Assembly.GetCallingAssembly();

            using (var runner = AssemblyRunner.WithoutAppDomain("AWSLambdaSeleniumTest.dll"))
            {
                runner.OnDiscoveryComplete = OnDiscoveryComplete;
                runner.OnExecutionComplete = OnExecutionComplete;
                runner.OnTestFailed        = OnTestFailed;
                runner.OnTestSkipped       = OnTestSkipped;

                LambdaLogger.Log("Discovering tests...\n");
                runner.Start();

                finished.WaitOne();  // A ManualResetEvent
                finished.Dispose();
            }

            return("");
        }
Пример #16
0
        public void RunAssemblyTests(Assembly assembly)
        {
            using AssemblyLoadContext.ContextualReflectionScope scope = AssemblyLoadContext.EnterContextualReflection(assembly);

            using ManualResetEvent testsCompleted = new ManualResetEvent(false);
            using AssemblyRunner runner           = AssemblyRunner.WithoutAppDomain(assembly.Location);

            runner.OnTestFailed += info =>
            {
                this.ProjectData.Points.TryGetValue(info.TestDisplayName, out HashSet <string>?points);

                this.AddTestResult(MethodTestResult.FromFail(info, points));
            };

            runner.OnTestPassed += info =>
            {
                this.ProjectData.Points.TryGetValue(info.TestDisplayName, out HashSet <string>?points);

                this.AddTestResult(MethodTestResult.FromSuccess(info, points));
            };

            runner.OnExecutionComplete += info =>
            {
                testsCompleted.Set();
            };

            //This is non blocking call!
            runner.Start();

            //We don't want to exit before all of the tests have ran
            //This will be signaled once all of the tests have been ran
            testsCompleted.WaitOne();

            //OnExecutionComplete is invoked before setting the Status so spin here until it changes
            SpinWait.SpinUntil(() => runner.Status == AssemblyRunnerStatus.Idle);

            //Give up the time slice
            //Travis sometimes fails inside the xUnit thread pool while trying to wait for completion
            //Try to fix this by trying to give the time slice to the thread pool thread
            Thread.Sleep(1);
        }
        public async Task Run()
        {
            using (var runner = AssemblyRunner.WithoutAppDomain(_AssemblyPath))
            {
                var tcs = new TaskCompletionSource <object>();
                runner.OnExecutionComplete = info => tcs.SetResult(null);
                runner.TestCaseFilter      = testCase => testCase.TestMethod.Method.Name == _MethodName;

                runner.OnTestPassed  = info => _OnTestFinished(new TestPassed(info.TestDisplayName, info.ExecutionTime, info.Output));
                runner.OnTestFailed  = info => _OnTestFinished(new TestFailed(info.TestDisplayName, info.ExecutionTime, info.Output, new[] { info.ExceptionType }, new[] { info.ExceptionMessage }, new[] { info.ExceptionStackTrace }));
                runner.OnTestSkipped = info => _OnTestFinished(new TestSkipped(info.TestDisplayName, info.SkipReason));

                runner.Start(_TypeName);

                await tcs.Task;
                // We can't dispose AssemblyRunner as long as it's not idle
                // The AssemblyRunner will be idle shortly after we get the `OnExecutionComplete` notification.
                // So we have to wait on another thread for the AssemblyRunner to be idle.
                await Task.Run(() => SpinWait.SpinUntil(() => runner.Status == AssemblyRunnerStatus.Idle));
            }
        }
Пример #18
0
        public static int Main()
        {
            NSApplication.Init();

            var testAssembly = typeof(Program).Assembly;

            using (var runner = AssemblyRunner.WithoutAppDomain(testAssembly.FullName))
            {
                runner.OnDiscoveryComplete = OnDiscoveryComplete;
                runner.OnExecutionComplete = OnExecutionComplete;
                runner.OnTestFailed        = OnTestFailed;
                runner.OnTestSkipped       = OnTestSkipped;

                Console.WriteLine("Discovering...");
                runner.Start(null);

                _finished.WaitOne();
                _finished.Dispose();

                return(_result);
            }
        }
Пример #19
0
        public static int Run(string testAssembly, string typeName)
        {
            // Start out assuming success; we'll set this to 1 if we get a failed test
            result_ = 0;

            using (var runner = AssemblyRunner.WithoutAppDomain($"{testAssembly}.dll"))
            {
                finished_ = new ManualResetEvent(false);

                runner.OnExecutionComplete = OnExecutionComplete;
                runner.OnTestFailed        = OnTestFailed;
                runner.OnTestSkipped       = OnTestSkipped;
                runner.OnTestPassed        = OnTestPassed;

                runner.Start(typeName, parallel: false);

                finished_.WaitOne();
                finished_.Dispose();
            }

            return(result_);
        }
Пример #20
0
        private AssemblyRunner CreateRunner(HashSet <string> tests, string assemblyPath)
        {
            var runner = AssemblyRunner.WithoutAppDomain(assemblyPath);

            runner.OnExecutionComplete = OnTestSessionEnd;
            runner.OnDiscoveryComplete = OnTestSessionStart;

            runner.OnTestFailed  = OnTestFailed;
            runner.OnTestPassed  = OnTestPassed;
            runner.OnTestSkipped = OnTestSkipped;

            runner.OnTestStarting = OnTestStart;
            runner.OnTestOutput   = OnTestOutput;
            runner.OnErrorMessage = OnTestError;

            if (tests != null)
            {
                runner.TestCaseFilter = testCase => tests.Contains(testCase.DisplayName);
            }

            return(runner);
        }
Пример #21
0
        public List <TestExecutionViewModel> Run(string context)
        {
            using (var runner = AssemblyRunner.WithoutAppDomain(context))
            // using (var runner = AssemblyRunner.WithoutAppDomain($"../Vlerx.SampleService.TestServer/bin/Debug/netcoreapp3.1/Vlerx.SampleService.Tests.dll"))
            {
                runner.OnDiscoveryComplete = OnDiscoveryComplete;
                runner.OnExecutionComplete = OnExecutionComplete;
                runner.OnTestPassed        = OnTestPassed;
                runner.OnTestFailed        = OnTestFailed;
                runner.OnTestSkipped       = OnTestSkipped;

                Console.WriteLine("Discovering...");
                runner.Start();

                Finished.WaitOne();  // A ManualResetEvent
                Finished.Dispose();
                Console.WriteLine("Done...");
                Console.WriteLine(JsonConvert.SerializeObject(Result));

                return(Result);
            }
        }
Пример #22
0
        public int Run(Action <AssemblyRunner> configureRunner = null)
        {
            var targetAssembly = GetTargetAssemblyFilename(this.testAssembly);

            using (var runner = AssemblyRunner.WithoutAppDomain(targetAssembly))
            {
                using (this.done = new ManualResetEvent(false))
                {
                    runner.OnDiscoveryComplete = this.OnDiscoveryComplete;
                    runner.OnExecutionComplete = this.OnExecutionComplete;
                    runner.OnTestFailed        = this.OnTestFailed;
                    runner.OnTestSkipped       = this.OnTestSkipped;

                    configureRunner?.Invoke(runner);

                    runner.Start();

                    this.done.WaitOne();
                }

                return(this.result);
            }
        }
Пример #23
0
        public static void Run(string testAssembly, TelemetryClient TelemetryClient, string typeName = null)
        {
            telemetryClient = TelemetryClient;
            Console.WriteLine("Running in TestRunner.Run()");
            using (var runner = AssemblyRunner.WithoutAppDomain(testAssembly))
            {
                runner.OnDiscoveryComplete = OnDiscoveryComplete;
                runner.OnExecutionComplete = OnExecutionComplete;
                runner.OnTestStarting      = OnTestStarting;
                runner.OnTestFailed        = OnTestFailed;
                runner.OnTestSkipped       = OnTestSkipped;
                runner.OnTestPassed        = OnTestPassed;
                runner.OnDiagnosticMessage = OnDiagnosticMessage;

                telemetryClient.TrackTrace("Discovering...", SeverityLevel.Information);
                runner.Start(typeName);

                finished.WaitOne();
                finished.Dispose();

                //return result;
            }
        }
Пример #24
0
        private static void RunTests()
        {
            var      testProjectAssembly = $@"..\sample-test-project\bin\Debug\netcoreapp2.2\publish\sample-test-project.dll";
            Assembly assembly            = Assembly.LoadFrom(testProjectAssembly);
            var      runner = AssemblyRunner.WithoutAppDomain(assembly.Location);

            runner.OnTestFinished      = TestFinished;
            runner.OnTestPassed        = TestPassed;
            runner.OnTestSkipped       = TestSkipped;
            runner.OnDiscoveryComplete = DiscoveryComplete;
            runner.OnErrorMessage      = Error;
            runner.OnExecutionComplete = ExecutionComplete;
            runner.OnTestFailed        = TestFailed;
            runner.OnTestOutput        = TestOutput;
            runner.TestCaseFilter      = FilterTests;
            runner.Start();

            while (runner.Status != AssemblyRunnerStatus.Idle)
            {
                Thread.Sleep(500);
                Console.WriteLine($"AssemblyRunnerStatus:{runner.Status}");
            }
            runner.Dispose();
        }
Пример #25
0
        static int _Result = 0;                                                // Start out assuming success; we'll set this to 1 if we get a failed test.

        public static int Point(string[] args)                                 // args[1] has to be the name of the test assembly without extension.
        {
            var testAssembly = args[1];

            using (var runner = AssemblyRunner.WithoutAppDomain(testAssembly)) {
                runner.OnDiscoveryComplete = OnDiscoveryComplete;
                runner.OnExecutionComplete = OnExecutionComplete;
                runner.OnTestFailed        = OnTestFailed;
                runner.OnTestSkipped       = OnTestSkipped;
                R("Discovering...");
                Start("");
                _Finished.WaitOne(-1);
                Thread.Sleep(10);
                _Finished.Dispose();

                void Start(string type)
                {
                    runner.Start(type, diagnosticMessages: true, null, null, null, // Runs start here.
                                 parallel: true, maxParallelThreads: 3, null);
                }

                return(_Result);
            }
        }
Пример #26
0
        static int Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            var dllPath = System.Reflection.Assembly.GetEntryAssembly().Location;

            // OpenCoverをつかうなら同じAppDomainである必要あり
            // using (var runner = AssemblyRunner.WithAppDomain(dllPath))
            using (var runner = AssemblyRunner.WithoutAppDomain(dllPath))
            {
                runner.OnDiscoveryComplete = OnDiscoveryComplete;
                runner.OnExecutionComplete = OnExecutionComplete;
                runner.OnTestFailed        = OnTestFailed;
                runner.OnTestSkipped       = OnTestSkipped;

                Console.WriteLine("Discovering...");
                runner.Start(null);

                finished.WaitOne();
                finished.Dispose();

                return(result);
            }
        }
Пример #27
0
 public static void Test()
 {
     using (var assemblyRunner = AssemblyRunner.WithoutAppDomain(typeof(Tests).Assembly.Modules.First().FullyQualifiedName))
     {
     }
 }
Пример #28
0
        private static int Main()
        {
            object consoleLock = new object();
            int    result      = 0;

            using (AssemblyRunner runner = AssemblyRunner.WithoutAppDomain(
                       Assembly.GetExecutingAssembly().Location
                       ))
                using (ManualResetEvent finished = new ManualResetEvent(false))
                {
                    runner.OnDiscoveryComplete = info =>
                    {
                        lock (consoleLock)
                        {
                            Console.WriteLine(
                                $"Running {info.TestCasesToRun} of {info.TestCasesDiscovered} tests..."
                                );
                        }
                    };
                    runner.OnExecutionComplete = info =>
                    {
                        lock (consoleLock)
                        {
                            Console.WriteLine(
                                "Finished: {0} tests in {1}s ({2} failed, {3} skipped)",
                                info.TotalTests,
                                Math.Round(info.ExecutionTime, 3),
                                info.TestsFailed,
                                info.TestsSkipped
                                );
                        }

                        finished.Set();
                    };
                    runner.OnTestFailed = info =>
                    {
                        lock (consoleLock)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;

                            Console.WriteLine(
                                "[FAIL] {0}: {1}",
                                info.TestDisplayName,
                                info.ExceptionMessage
                                );
                            if (info.ExceptionStackTrace != null)
                            {
                                Console.WriteLine(info.ExceptionStackTrace);
                            }

                            Console.ResetColor();
                        }

                        result = 1;
                    };
                    runner.OnTestSkipped = info =>
                    {
                        lock (consoleLock)
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;

                            Console.WriteLine("[SKIP] {0}: {1}", info.TestDisplayName, info.SkipReason);

                            Console.ResetColor();
                        }
                    };

                    Console.WriteLine("Discovering...");
                    runner.Start(null);
                    finished.WaitOne();

                    return(result);
                }
        }
Пример #29
0
 /// <summary>
 /// Creates an assembly runner that discovers and runs tests without a separate app domain.
 /// </summary>
 /// <param name="assemblyFileName">The test assembly.</param>
 public XUnitTestRunner(string assemblyFileName)
 {
     _assemblyRunner = AssemblyRunner.WithoutAppDomain(assemblyFileName);
 }