public void TestKill() { Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe")); using (AssemblyRunner runner = new AssemblyRunner(Exe)) { ManualResetEvent gotExit = new ManualResetEvent(false); runner.ProcessExited += delegate(Object o, ProcessExitedEventArgs e) { gotExit.Set(); }; Assert.IsFalse(runner.IsRunning); runner.Kill(); // always safe to call runner.Start("-wait"); Assert.IsTrue(runner.IsRunning); try //make sure we can't start twice. { runner.Start(); Assert.Fail(); } catch (InvalidOperationException) { } Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), false)); runner.Kill(); Assert.IsFalse(runner.IsRunning); Assert.IsTrue(gotExit.WaitOne(30000, false)); } }
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(); }
protected override TestExecutionResults ExecuteImpl(string testModule, IEnumerable <IMemberDefinition> testsToRun, string[] args) { if (!testsToRun.Any()) { // discovery cannot be done // When running with empty list of tests XUnit hangs return(new TestExecutionResults()); } executedTests.Clear(); this.testsToRun = testsToRun; executionCanceled = false; result = new TestExecutionResults(); runner = AssemblyRunner.WithAppDomain(testModule); logger.Debug($"Running XUnit executor in App domain: {AppDomain.CurrentDomain.FriendlyName}"); runner.TestCaseFilter = TestCaseFilterHandler; runner.OnExecutionComplete = ExecutionCompleteHandler; runner.OnTestFailed = TestFailedHandler; runner.OnTestFinished += TestFinishedHandler; runner.OnDiscoveryComplete += DiscoveryCompleteHandler; runner.OnErrorMessage += ErrorMessageHandler; logger.Debug("Starting tests"); runner.Start(maxParallelThreads: 1); finished.WaitOne(); finished.Dispose(); while (runner.Status != AssemblyRunnerStatus.Idle && !executionCanceled) { // spin until runner finishes } if (executionCanceled) { try { runner.Dispose(); } catch (InvalidOperationException e) { // for now ignore this exception // due to XUnit bug of not resetting Status to Idle when cancelling run } } else { runner.Dispose(); } var temp = result; // reset result variable result = null; return(temp); }
public void TestStandardInputFail() { using (IRunner runner = new AssemblyRunner(Exe)) { runner.Start("-wait"); runner.StandardInput.WriteLine(); } }
public void TestUnhandledExceptionWaitForExit() { using (IRunner runner = new AssemblyRunner(Exe)) { runner.Start("-throw", "System.ArgumentOutOfRangeException"); runner.WaitForExit(); Assert.Fail(); } }
private static void RunAllTests(AssemblyRunner runner) { using var executionCompleteEvent = new ManualResetEvent(false); var onExecutionComplete = runner.OnExecutionComplete; runner.OnExecutionComplete += info => executionCompleteEvent.Set(); runner.Start(); executionCompleteEvent.WaitOne(); runner.OnExecutionComplete = onExecutionComplete; }
private void RunTests(AssemblyRunner runner) { try { runner.Start(); } catch (Exception ex) { LogTo.ErrorException("Failed to unload test runner", ex); _finished.Set(); } }
public void Run() { string typeName = null; bool diagnosticMessages = true; TestMethodDisplay methodDisplay = TestMethodDisplay.Method; bool preEnumerateTheories = true; bool parallel = false; int?maxParallelThreads = null; impl.Start(typeName, diagnosticMessages, methodDisplay, preEnumerateTheories, parallel, maxParallelThreads); completed.WaitOne(); }
private static void Run(AssemblyRunner runner, int[] result, string typeName) { if (typeName != null && string.IsNullOrWhiteSpace(typeName)) throw new ArgumentException("The test type name cannot be white space."); // Use an event to know when we're done using (var finished = new ManualResetEvent(false)) { // We use consoleLock because messages can arrive in parallel, so we want to make sure we get // consistent console output. var consoleLock = new object(); SetupRunnerCallbacks(runner, finished, consoleLock, result); runner.Start(typeName); finished.WaitOne(); // Wait for tests to complete. } }
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(); }
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 void RunTestsClicked() { try { GD.Print("Tests starting"); AssemblyRunner runner = Xunit.Runners.AssemblyRunner.WithoutAppDomain(Assembly.GetExecutingAssembly().Location); runner.OnTestStarting = info => { GD.Print($"Running {info.TestDisplayName}"); }; runner.OnTestPassed = info => { GD.Print($"{info.TestDisplayName} passed"); }; runner.OnTestFailed = info => { GD.Print($"{info.TestDisplayName} failed"); }; runner.OnTestOutput = info => { GD.Print($"{info.TestDisplayName}: {info.Output}"); }; runner.OnExecutionComplete = info => { GD.Print($"Tests completed in {info.ExecutionTime}"); GD.Print($"Total tests: {info.TotalTests}"); GD.Print($"Failed tests: {info.TestsFailed}"); GD.Print($"Skipped tests: {info.TestsSkipped}"); }; runner.Start(); } catch (Exception e) { GD.Print(e.Message); } }
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); } }